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.

Using the storefront api to create checkout

Using the storefront api to create checkout

AlmaKnit
Tourist
4 0 1

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)