Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Shopify GraphQL Mutation Doesn't Work In CURL or Postman But Does With GraphiQL App

Shopify GraphQL Mutation Doesn't Work In CURL or Postman But Does With GraphiQL App

Itachi_Uchiha
Shopify Partner
26 0 1

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! 

 

 

 

Replies 3 (3)

Liam
Community Manager
3108 342 884

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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

Itachi_Uchiha
Shopify Partner
26 0 1

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?

Liam
Community Manager
3108 342 884

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