A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I am using the example here:
https://shopify.dev/tutorials/manage-product-media-with-admin-api
I am almost copying and pasting the code, so I don't understand why I am getting an HTTP response"
{"errors":[{"message":"Unexpected end of document","locations":[]}]}
I am using Python.
Solved! Go to the solution
This is an accepted solution.
I found a post that describes this error with python requests.
The trick is you have to change the 'Content-Type' header to 'application/json'.
Then I had to change the post string to:
r = requests.post(url,json={"query": query, "variables": params}, headers=headers)
https://github.com/Shopify/graphql-js-client/issues/132
This is how you post to GraphQL using Python request. This may be very helpful to other people.
Testing things out using the GraphiQL app, it appears as if the mediaUserErrors property isn't part of the available field set. Here was the error I got back.
{
"errors": [
{
"message": "Field 'mediaUserErrors' doesn't exist on type 'StagedUploadsCreatePayload'",
"locations": [
{
"line": 11,
"column": 5
}
],
"path": [
"mutation generateStagedUploads",
"stagedUploadsCreate",
"mediaUserErrors"
],
"extensions": {
"code": "undefinedField",
"typeName": "StagedUploadsCreatePayload",
"fieldName": "mediaUserErrors"
}
}
]
}
When I removed that the GQL request went through just fine. Screen shot below. I'd recommend checking your Python code to ensure that it's properly formatting the GQL request. You can always fire up Fiddler or something to see exactly what's being sent out in the request body.
I don’t understand anything that was sent just now. Please remember that I just closed the account and it was on paused before so I would not be able to go back on it to request a refund
This is an accepted solution.
I found a post that describes this error with python requests.
The trick is you have to change the 'Content-Type' header to 'application/json'.
Then I had to change the post string to:
r = requests.post(url,json={"query": query, "variables": params}, headers=headers)
https://github.com/Shopify/graphql-js-client/issues/132
This is how you post to GraphQL using Python request. This may be very helpful to other people.