Creating checkout instance storefront api with Apollo's useMutation

omergeva
Visitor
1 0 0

Hi,
I'm trying to create a checkout instance using the useMutation hook.
I know my client is set up properly as I'm able to make queries for items in my store.
Whenever I call the function to create the checkout instance, I get 
Error: Unexpected end of JSON input

Appreciate the help!!

Calling query:

 

  const [createCheckout, { data, loading, error }] = useMutation(CHECKOUT_CREATE_MUTATION);
  const handleOnAddToCart = async () => {
    await createCheckout();
    await console.log(data);   
  }

 

Checkout query: 

 

  const CHECKOUT_CREATE_MUTATION = gql`
  mutation checkoutCreate {
    checkoutCreate(input: {}) {
      checkout {
        id
      }
    }
  }
  `;​

 

 (I was originally trying to create it using an actual line item, but after that didn't work I figured to just try to create the checkout instance first).

Reply 1 (1)
ncuillery
Shopify Partner
1 0 0

For me, that was because this request header was missing: Accept: application/json

 

Apparently, this header is mandatory for mutations (not queries)