Discussing Shopify Functions development, deployment, and usage in Shopify apps.
When I'm using the following mutation in GraphiQL App it works perfectly but when I run it using Postman or CURL it just doesn't work. This issue is happening for Function related mutations only.
mutation { discountAutomaticAppCreate( automaticAppDiscount: { title: "Volume Discount Created from APP 011", functionId: "9d8aas8-78asd-8d7sa-86f0-dg789asdfa9sd", startsAt: "2023-09-19T00:00:00"} ) { # Payload userErrors { code field message } automaticAppDiscount { discountId title status createdAt endsAt } } }
The error that I get when using CURL or Postman is:
"data": { "discountAutomaticAppCreate": { "userErrors": [ { "code": "INVALID", "field": [ "automaticAppDiscount", "functionId" ], "message": "Function not found." } ], "automaticAppDiscount": null } },
Later I also rechecked the "shop-name" and "api-version" both in GraphiQL and CURL, Postman. They all had same shop-name and api-version.
What can I do to solve the problem? Thanks!
Based on the response error you're getting, it seems that the "Function not found" error is related to the "functionId" field, but it is unusual that it's working as expected with the GraphiQL App.
Here are a few things you can check:
Check your Access Tokens: When running your mutations through CURL or Postman, you need to provide an access token in the headers to authenticate your request. Make sure you're using a valid access token that has the necessary permissions to access and modify the functions in the Shopify store.
Check your headers: Along with the access token, ensure that you have set correct headers for 'Content-Type' as 'application/json' and 'X-Shopify-Access-Token' as your actual access token in your CURL or Postman request.
Review your GraphQL syntax: Make sure your mutation is correctly formatted as per GraphQL syntax. Also, check if all the necessary fields are included in the mutation.
Try refreshing your tokens: Sometimes tokens can get expired or invalidated, try refreshing your tokens.
If you've checked all these and still getting the error, it might be an issue that needs to be looked at by the Shopify support team. You can reach out to them via your Partner Dashboard with the details of the issue.
Hope this helps,
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi Liam.
Do I use the same access token that I've derived from this process or do I've to use some other access token?
You would need to use an access token, as is described here. There may be authentication required to allow you to make requests from curl/postman.
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog