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.

get error when try to create cart with storefront api

get error when try to create cart with storefront api

Rakibul_Hasan
Visitor
3 0 0

i use this mutation to create the cart:

mutation createCart {
    cartCreate(
      input: {
        buyerIdentity: {
          email: "example-email@example.com"
          customerAccessToken: "f08ec7d6418751178caa565233"
        }
        lines: [
          { quantity: 2, merchandiseId: "gid://shopify/Product/8318551621920" }
        ]
      }
    ) {
      cart {
        buyerIdentity {
          email
        }
        lines(first: 10) {
          edges {
            node {
              quantity
            }
          }
        }
      }
    }
  }

 when i use this in shopify graphiql playground  get the given below error:  

{
  "data": {
    "cartCreate": null
  },
  "errors": [
    {
      "message": "invalid id",
      "locations": [
        {
          "line": 2,
          "column": 5
        }
      ],
      "path": [
        "cartCreate"
      ]
    }
  ]
}

it said invalid id but I am not able to find which wrong id I am providing. Please someone help me to solve the error

Reply 1 (1)

sanchay
Shopify Partner
2 0 0

You provide product ID. So that reason the Invalid ID error shows. You replace the product ID with the product variant ID like below code.

mutation createCart {
    cartCreate(
      input: {
        buyerIdentity: {
          email: "example-email@example.com"
          customerAccessToken: "f08ec7d6418751178caa565233"
        }
        lines: [
          { quantity: 2, merchandiseId: "gid://shopify/ProductVariant/47860404748574" }
        ]
      }
    ) {
      cart {
        buyerIdentity {
          email
        }
        lines(first: 10) {
          edges {
            node {
              quantity
            }
          }
        }
      }
    }
  }