Can't run bulk operation --"Failed to parse the mutation - Unexpected end of document"

Topic summary

A user encountered a “Failed to parse the mutation - Unexpected end of document” error when running a bulk operation mutation in Shopify’s GraphQL API.

Root Cause Identified:
The error stemmed from a syntax mistake in the callback query portion of the mutation. The user had incorrectly nested the variants field inside the id field:

  • Incorrect: {product {id {variants(first: 20) {nodes {id sku}}}}}
  • Correct: {product {id variants(first: 20) {nodes {id sku}}}}

Resolution:
Removing the extra curly braces around id fixed the issue.

User Feedback:
The user noted that the error message was misleading—it had nothing to do with “unexpected end of document” and suggested Shopify could improve error messaging to better pinpoint syntax issues.

Summarized with AI on November 25. AI used: claude-sonnet-4-5-20250929.

query:

mutation {bulkOperationRunMutation(mutation: "mutation call($input: ProductInput!) {productUpdate(input: $input) {product  {id {variants(first: 20) {nodes {id sku}}}}}",   stagedUploadPath: "tmp/63578079486/bulk/62552451-7eba-4cc1-85df-c947a5559999/1669363450") {bulkOperation {id  url status} userErrors {message field}}}

response:

{"data":{"bulkOperationRunMutation":{"bulkOperation":null,"userErrors":[{"message":"Failed to parse the mutation - Unexpected end of document","field":null}]}},"extensions":{"cost":{"requestedQueryCost":10,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":2000.0,"currentlyAvailable":1990,"restoreRate":100.0}}}}

input file:

{"input":{"id":"gid:\/\/shopify\/Product\/7931585659999","privateMetafields":[{"namespace": "product", "key": "matrixify", "valueInput": {"value": "1", "valueType": "STRING"}}]}}
{"input":{"id":"gid:\/\/shopify\/Product\/7931587499999","privateMetafields":[{"namespace": "product", "key": "matrixify", "valueInput": {"value": "1", "valueType": "STRING"}}]}}
{"input":{"id":"gid:\/\/shopify\/Product\/7931588119999","privateMetafields":[{"namespace": "product", "key": "matrixify", "valueInput": {"value": "1", "valueType": "STRING"}}]}}

The same query works on another store

I can verify the file from the “StagedUploadPath” exists. It returns the records I’d previously submitted.

I cannot find this error any place. There are not google references to it.

Thank you

It was the callback query: {product {id {variants(first: 20) {nodes {id sku}}}}}

Should have been {product {id variants(first: 20) {nodes {id sku}}}}

However, the syntax error had absolutely nothing to do with “Failed to parse the mutation - Unexpected end of document”. A little better error codes, Shopify.