Using the storefront api to create checkout

AlmaKnit
Visitor
3 0 0

I am trying to create a checkout with the Storefront API but I keep getting an "Parameter Missing or Invalid" error. My code is as follows. Can anyone help me with what I am doing wrong?

 

const checkoutQuery = () => `
    mutation createCheckout @inContext(language: EN) {
      checkoutCreate(input: {
        lineItems: [{variantId: "xxxxx", quantity: 1, customAttributes: [{ key: "yyyy", value: "zzzz"}]}]
     }) {
        checkout {
          webUrl
        }
      }
    }
`;

const GRAPHQL_BODY = () => {
      return {
         method: 'POST',
        headers: {
          'X-Shopify-Storefront-Access-Token': SHOPIFY_ACCESS_TOKEN,
          'Content-Type': 'application/graphql',
          Accept: "application/json"
        },
        body: checkoutQuery()
      };
    }

  const GRAPHQL_URL = "https://example.myshopify.com/api/2022-10/graphql.json"


    return jQuery.ajax(GRAPHQL_URL, GRAPHQL_BODY())
      .then((res) => {
        setCheckout(res);
        return res.webUrl;
      });

 

Replies 0 (0)