merce.STACK
merce.STACK
Skip to content
PricingDevelopersSecurityAbout
Log inGet started

Commerce API

  • Quickstart
  • Keys & authentication
  • Products & catalog
  • Carts
  • Checkout & payment
  • Digital products
  • Webhooks
  • Errors
  • Without a build step
  • API reference

Commerce API

Errors

One error type, stable codes. Branch on the code, never the text.

import { MercestackError } from "@mercestack/commerce";

try {
  await mercestack.addToCart({ variantId });
} catch (error) {
  if (error instanceof MercestackError) {
    error.code;         // "OUT_OF_STOCK"
    error.status;       // 400
    error.requestId;    // quote this to support
    error.isRetryable;  // network, rate limit, 5xx
    error.details;      // anything else the API sent
  }
}

Messages are written for humans and get rewritten. A client that does if (message.includes("out of stock")) breaks the day somebody improves the wording — branch on code.

CodeWhat happened
OUT_OF_STOCKNot enough available, and backorders are off
PRODUCT_NOT_AVAILABLEUnpublished or archived since it was added
INVALID_VARIANTNo such variant in this store
PRICE_CHANGEDThe price moved between display and checkout
CART_EXPIREDUntouched too long. The SDK recovers from this for you
CART_EMPTYNothing to check out
DISCOUNT_INVALIDExpired, exhausted, or never existed
GIFT_CARD_INVALIDWrong code, cancelled, expired, or empty
PAYMENT_FAILEDThe provider declined it
UNAUTHORIZEDMissing or revoked key
FORBIDDENKey exists but is not allowed to do this
RATE_LIMITEDToo many requests. Back off and retry

Every response carries a Mercestack-Request-Id header, and it matches a line in Commerce → Developers → API logs. It is the fastest way to have someone find out what actually happened.

The SDK retries transient failures — network errors, rate limits, 5xx — with exponential backoff. It does not retry a 400: that is the same wrong request sent again.

PreviousWebhooksNextWithout a build step
Create a workspaceTalk to usPricing

The business operating system. One workspace for structure, customers, communication, money and the automation between them.

Create your workspace

Platform

  • Overview
  • Structure & work
  • Customers & communication
  • Finance & commerce
  • Flow & AI Workforce
  • Analytics & files

Developers

  • Documentation
  • Quickstart
  • Keys & authentication
  • Carts & checkout
  • Webhooks
  • API reference

Company

  • About
  • Pricing
  • Security
  • Contact
  • Report a vulnerability

Legal

  • Privacy
  • Terms
  • Cookie policy
  • GDPR
  • Privacy contact

© 2026 Mercestack. All rights reserved.

Mercestack StructureOS