How to use variables on BulkOperations with GraphQL?

Solved
Highlighted
Shopify Partner
13 1 0

Hey, so I want to use variables to query using bulkOperationRunQuery, but it gives me an error like this:

"userErrors": [
        {
          "field": [
            "query"
          ],
          "message": "Variable q of type String! was provided invalid value"
        }
      ]

this is my query:

mutation {
    bulkOperationRunQuery(
      query:"""
        query bulkProduct($q:String!){
          products(query: $q) {
            edges {
              node {
                id
                createdAt
                updatedAt
                title
              }
            }
          }
        }
      """
    ) {
      bulkOperation {
        id
        status
      }
      userErrors {
        field
        message
      }
    }
  }

this is my variable:

{
  "q":"tag:airbus"
}

Thank you in advance!

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 103 124

This is an accepted solution.

Hey @aldoalprak ,

 

Since the Bulk Operations API works by providing a hardcoded string of your query into a bulkOperationRunQuery mutation, you cannot utilize variables in your query. You have to hardcode all your values in the query string.

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes