404 error using node.js checkoutAPI

I’m trying to use square hosted checkout for my pizza business. It looks as though the data I’m sending is valid, as I had various issues I fixed with validity before this one. I was getting 401 errors for a bit, so changed my access token, and now I’m getting 404s.

Any help would be appreciated,


const uuid = require("uuid");

const { Client, Environment } = require("square");

const locationId = "LV9V6ND34HHBS";
const squareAccessToken =
  process.env.squareAccessToken ||
const client = new Client({
  environment: Environment.Sandbox,
  accessToken: squareAccessToken

app.post("/api/checkout", async (req, res) => {
  const pizzas = req.body.pizzas;
  const response = await client.checkoutApi.createCheckout(
  return res.status(200).send("OK");

function convertPizzasToCheckoutRequest(pizzas) {
  const lineItems = pizzas.map((pizza) => {
    const itemName = { sm: "Small", lg: "Large" }[pizza.size].concat(" Pizza");

    const prunedToppings = pizza.toppings.filter((t) => t !== "Mozzarella");

    //todo fix pluralisation
    const variation = `With ${prunedToppings.length} toppings`;
    const note = prunedToppings.reduce((toppingList, topping) => {
      if (toppingList === "") return topping;
      return toppingList.concat(`, ${topping}`);
    }, "");

    const basePrice =
      { sm: 3, lg: 6 }[pizza.size] +
      { sm: 0.5, lg: 1 }[pizza.size] * prunedToppings.length;

    return {
      idempotencyKey: uuid.v4(),
      quantity: 1,
      name: itemName,
      variation_name: variation,
      base_price_money: { amount: basePrice, currency: "GBP" }
  return {
    order: { locationId, line_items: lineItems },
    idempotencyKey: uuid.v4(),
    ask_for_shipping_address: true

Never mind, solved it myself.

When I changed my API key, the locationID also changed. Since the locationID is in the path as opposed to the body, I got a 404 back instead of the errors from the servers I was getting previously.

Hope this helps anyone making the same mistake as me,