Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

createCart returns 404 with HTML response

AlexanderWeb
Shopify Partner
5 0 0

When the following mutation is invoked I get an error which returns an HTML response:

 

const graphQLClient = new GraphQLClient(endpoint as string, {
  headers: {
    "X-Shopify-Storefront-Access-Token": storefrontAccessToken,
  } as any,
});

 

export async function addToCart(itemId: string, quantity: string) {
  const createCartMutation = gql`
    mutation createCart($cartInput: CartInput) {
      cartCreate(input: $cartInput) {
        cart {
          id
        }
      }
    }
  `;

  const variables = {
    cartInput: {
      lines: [
        {
          quantity: parseInt(quantity),
          merchandiseId: itemId,
        },
      ],
    },
  };
  try {
    await graphQLClient.request(createCartMutation, variables);
  } catch (error: any) {
    // error happening in this catch
    throw new Error(error);
  }
}

 

Screenshot 2023-06-03 at 19.40.12.png

Screenshot 2023-06-03 at 19.40.21.png

  

 
Replies 0 (0)