1
votes

I cannot create a checkout with Shopify's Graphql API

I am literally copying the example from this page in Shopify's Checkout Guide and pasting it into Shopify's GraphiQL App installed on the store where I am trying to create the checkout.

This is my mutation, where the only thing I changed was the variantId so it matches one on my store:

mutation {
  checkoutCreate(input: {
    lineItems: [{ variantId: "gid://shopify/ProductVariant/46037988422", quantity: 1 }]
  }) {
    checkout {
       id
       webUrl
       lineItems(first: 5) {
         edges {
           node {
             title
             quantity
           }
         }
       }
    }
  }
}

This is the response I'm getting from Shopify:

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

The weird thing is that obviously checkoutCreate IS a mutation, according to Shopify. See the link to the page here

Then I noticed, that the mutation on that page is different. So I'm trying that version, without a variable like this:

mutation checkoutCreate(input: {
    lineItems: [{ variantId: "gid://shopify/ProductVariant/46037988422", quantity: 1 }]
  }) {
    checkout {
      id
    }
    checkoutUserErrors {
      code
      field
      message
    }
}

And now the error I'm getting back is:

{
  "errors": [
    {
      "message": "Parse error on \"input\" (INPUT) at [1, 25]",
      "locations": [
        {
          "line": 1,
          "column": 25
        }
      ]
    }
  ]
}

Finally I tried this version with a variable and it also failed:

mutation checkoutCreate($input: CheckoutCreateInput!) {
  checkoutCreate(input: $input) {
    checkout {
      id
    }
    checkoutUserErrors {
      code
      field
      message
    }
  }
}

{
  "input": {
    lineItems: [{ variantId: "gid://shopify/ProductVariant/46037988422", quantity: 1 }]
  }
}

The error here was:

{
  "errors": [
    {
      "message": "Parse error on \"input\" (STRING) at [15, 3]",
      "locations": [
        {
          "line": 15,
          "column": 3
        }
      ]
    }
  ]
}

On top of all this, Shopify has interactive docs in their GraphiQL App.. and it does NOT list checkoutCreate as an available mutation. See this screenshot: https://nimb.ws/af4iHx

2
I am facing the same Issue. Any updates?Tushar Pandey

2 Answers

0
votes

I believe your input is parsed as JSON, so try putting quotes even around the nested properties of your mutation variables when testing.

    {
      "input": {
        "lineItems": [{ "variantId": "gid://shopify/ProductVariant/46037988422", 
                    "quantity": 1 }]
     }
   }
0
votes

The mutations that complete checkouts are only available for sales channels. These apps must be public. So it might not work if you are creating a private app.

https://shopify.dev/tutorials/create-a-checkout-with-storefront-api https://shopify.dev/tutorials/authenticate-a-public-app-with-oauth#turn-an-app-into-a-sales-channel