createCart returns 404 with HTML response

Topic summary

A developer encounters a 404 error with an HTML response when executing a createCart mutation in Shopify’s Storefront API.

Setup:

  • Using GraphQLClient with storefront access token
  • Attempting to create a cart with merchandise ID and quantity

Issue:

  • The mutation returns a 404 error instead of the expected GraphQL response
  • Response format is HTML rather than JSON, suggesting the endpoint may be incorrect or inaccessible

Code includes:

  • GraphQL mutation for cartCreate
  • Variables structure with cartInput containing line items
  • Error handling in try-catch block

The discussion appears to show screenshots (referenced but content obscured), likely demonstrating the error response. No resolution or responses from other users are present yet. This remains an open troubleshooting request, with potential issues being incorrect endpoint configuration, invalid access token, or API permissions.

Summarized with AI on November 20. AI used: claude-sonnet-4-5-20250929.

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);
  }
}