A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello all,
I'm trying to perform a BulkOperationRunQuery mutation query in cURL but I'm having trouble getting the formatting correct. The query runs correctly in the GraphiQL app but I keep getting errors when running in cURL.
Here's the GraphiQL query:
mutation {
bulkOperationRunQuery(
query:"""
{
products {
edges {
node {
id
handle
tags
productType
variants {
edges {
node {
id
sku
price
compareAtPrice
inventoryItem {
id
unitCost {
currencyCode
amount
}
inventoryLevels {
edges {
node {
id
available
location {
id
name
}
}
}
}
}
}
}
}
}
}
}
}""")
{
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}
This is the cURL command I've cobbled together:
curl -X POST \
https://----------.myshopify.com/admin/api/2020-07/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token:----------------'\
-d ' {
"query": "mutation{bulkOperationRunQuery(query:"""{products{edges{node{id handle tags productType variants{edges{node{id sku price compareAtPrice inventoryItem{id unitCost{currencyCode amount}inventoryLevels{edges{node{id available location{id name}}}}}}}}}}}}"""){bulkOperation{id status}userErrors{field message}}}"
}'
But it results in this error:
{"error":"783: unexpected token at '{\n \"mutation\": \"mutation{bulkOperationRunQuery(query:\"\"\"{products{edges{node{id handle tags productType variants{edges{node{id sku price compareAtPrice inventoryItem{id unitCost{currencyCode amount}inventoryLevels{edges{node{id available location{id name}}}}}}}}}}}}\"\"\"){bulkOperation{id status}userErrors{field message}}}\"\n }'"}
I'm sure I'm not formatting the GraphQL query properly for cURL but not sure how to correct it.
Any help with this or even documentation links would be appreciated!
Cheers!
-C
The triple quotation marks need to be escaped with a backslash. For example:
curl -X POST https://XXXXX.myshopify.com/admin/api/2020-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: shpat_XXXXXXXX' \
-d '{"query" : "mutation { bulkOperationRunQuery( query:\"\"\" { products { edges { node { id vendor tags } } } } \"\"\" ){ bulkOperation { id status } userErrors { field message } } } " }'