Solved

graphql and shopify Field 'cartCreate' doesn't exist on type 'Mutation'

umang-pancholi
Shopify Partner
19 0 0
 mutation {
  cartCreate(
    input{
      lines[
        {
          quantity1
          merchandiseId"gid://shopify/ProductVariant/11157441773853"
        }
      ],
      # The information about the buyer that's interacting with the cart.
      buyerIdentity{
        email"example@example.com",
        deliveryAddressPreferences{
          deliveryAddress{
            address1"150 Elgin Street",
            address2"8th Floor",
            city"Ottawa",
            province"Ontario",
            country"ind",
            zip"395006"
          },
        }
      }
      attributes{
        key"cart_attribute",
        value"This is a cart attribute"
      }
    }
  ) {
    cart {
      id
      createdAt
      updatedAt
      lines(first10) {
        edges {
          node {
            id
            merchandise {
              ... on ProductVariant {
                id
              }
            }
          }
        }
      }
      buyerIdentity {
        deliveryAddressPreferences {
          __typename
        }
      }
      attributes {
        key
        value
      }
      # The estimated total cost of all merchandise that the customer will pay at checkout.
      cost {
        totalAmount {
          amount
          currencyCode
        }
        # The estimated amount, before taxes and discounts, for the customer to pay at checkout.
        subtotalAmount {
          amount
          currencyCode
        }
        # The estimated tax amount for the customer to pay at checkout.
        totalTaxAmount {
          amount
          currencyCode
        }
        # The estimated duty amount for the customer to pay at checkout.
        totalDutyAmount {
          amount
          currencyCode
        }
      }
    }
  }
}



error-------------->
{
    "errors": [
        {
            "message": "Field 'cartCreate' doesn't exist on type 'Mutation'",
            "locations": [
                {
                    "line": 3,
                    "column": 3
                }
            ],
            "path": [
                "mutation",
                "cartCreate"
            ],
            "extensions": {
                "code": "undefinedField",
                "typeName": "Mutation",
                "fieldName": "cartCreate"
            }
        }
    ]
}




Accepted Solutions (2)

Liam
Shopify Staff
2731 294 746

This is an accepted solution.

This does sound like a strange error as the cartCreate mutation is available on the storefront API, but here's a few things you could check to troubleshoot this:

 

  • Does the app have access to the Storefront API? You can enable this on your partner dashboard at Apps > App name > App Setup   
  • Are you using an up to date API version?
  • Are you using a client like Postman to run mutations? If so is there something on Postman's side which could be causing this?

Try the above and let us know if you're still seeing issues.

 

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

View solution in original post

ShopifyDevSup
Shopify Staff
1251 202 443

This is an accepted solution.

Hey @Umang-panholi

 

Thanks for confirming that. Testing this here, it looks like you're making the cartCreate mutation to the admin api instead of the storefront API. I received the exact same error when I tried cartCreate in the admin api. 

You'll want to make sure you're using your storefront access token and authenticating your request as described here: https://shopify.dev/docs/api/storefront#authentication

Once you're making requests to the storefront API, I did notice that your buyer identity fields have some errors (mainly incorrect country and zip). That is going to return some errors as well. 

 

I'd recommend for next steps to start with a very basic mutation, like the one provided below and then slowly add in the fields you need, testing each step of the way to catch those errors! 

 

mutation {
   cartCreate(
       input: {
           lines: [
               {
                   quantity: 1
                   merchandiseId: "gid://shopify/ProductVariant/11157441773853"
               }
           ]
       }
   ) {
       cart {
           id
           checkoutUrl
       }
       userErrors {
           field
           message
       }
   }
}

Hope that helps! 

 

- Kyle G. 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

View solution in original post

Replies 5 (5)

Liam
Shopify Staff
2731 294 746

This is an accepted solution.

This does sound like a strange error as the cartCreate mutation is available on the storefront API, but here's a few things you could check to troubleshoot this:

 

  • Does the app have access to the Storefront API? You can enable this on your partner dashboard at Apps > App name > App Setup   
  • Are you using an up to date API version?
  • Are you using a client like Postman to run mutations? If so is there something on Postman's side which could be causing this?

Try the above and let us know if you're still seeing issues.

 

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

umang-pancholi
Shopify Partner
19 0 0

umangpancholi_0-1701865017560.png

umangpancholi_1-1701865048677.png

 

 

umang-pancholi
Shopify Partner
19 0 0

grant all permissions but it isn't working.

ShopifyDevSup
Shopify Staff
1251 202 443

This is an accepted solution.

Hey @Umang-panholi

 

Thanks for confirming that. Testing this here, it looks like you're making the cartCreate mutation to the admin api instead of the storefront API. I received the exact same error when I tried cartCreate in the admin api. 

You'll want to make sure you're using your storefront access token and authenticating your request as described here: https://shopify.dev/docs/api/storefront#authentication

Once you're making requests to the storefront API, I did notice that your buyer identity fields have some errors (mainly incorrect country and zip). That is going to return some errors as well. 

 

I'd recommend for next steps to start with a very basic mutation, like the one provided below and then slowly add in the fields you need, testing each step of the way to catch those errors! 

 

mutation {
   cartCreate(
       input: {
           lines: [
               {
                   quantity: 1
                   merchandiseId: "gid://shopify/ProductVariant/11157441773853"
               }
           ]
       }
   ) {
       cart {
           id
           checkoutUrl
       }
       userErrors {
           field
           message
       }
   }
}

Hope that helps! 

 

- Kyle G. 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

umang-pancholi
Shopify Partner
19 0 0

your code is correct but it is work on storefront side...