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

mutation {
cartCreate(
input: {
lines: [
{
quantity: 1
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(first: 10) {
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”
}
}
]
}

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.

I grant all permissions but it isn’t working.

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.

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