Skip to content

Authentication

Every request to the EcomWeb API carries a key. There are three kinds. This guide shows which key to use, which header carries it, and what the API checks before it lets a request through. You need a key first. To create one, see Create and manage API keys.

The base URL for all examples is https://apibase.ecomweb.app/api/v1.

Secret key Publishable key Storefront secret key
Use it in Servers, scripts and CI Browser storefront code Your storefront’s server only
Header x-api-key x-storefront-api-key x-storefront-api-key
Reaches The Store API, limited by the key’s scopes The public Storefront API routes: catalog and content reads Every Storefront API route
Starts with sk_live_ pk_live_ sk_storefront_
How many As many as you create As many as you create As many as you create
Safe to expose No Yes, it is meant to ship in a storefront No
Shown again No Yes Yes, to the store owner only

A key belongs to one store and only works for that store. A key that starts with sk_live_ is the secret key in this guide. A storefront secret key is a different key, and it never works on the Store API.

Storefront API routes start with /api/v1/storefront/. The old /api/v1/public/stores/... paths answer 404 since API 4.0.0.

Every Storefront API route is either public or private. A publishable key reaches the public routes. A private route needs a storefront secret key. A storefront secret key works on every route, public ones included, so a server needs only that key.

The public routes are reads of catalog and content:

  • Products, product reviews, collections, categories and search, including autocomplete
  • Blog posts, categories, tags and comments (reads)
  • Content pages, menus and banners
  • Metaobjects (reads)
  • URL redirect lookups
  • The list of payment methods and shipping location areas
  • Store info by domain or by ref, the sitemap data and the theme preview
  • The store’s sign-in configuration
  • Promotions shown on the storefront (promotion suggestions)

Everything else is private. That includes the cart, orders and order lookup, payments, shopper sign-up and sign-in, the customer profile and addresses, metafield writes, product reviews that a shopper submits, blog comments that a shopper submits, shipping fee calculation, promotion code validation and web vitals. A route that is not marked public is private.

Send the key from your storefront’s server in the x-storefront-api-key header. This call adds a line to a guest cart:

Terminal window
curl -X POST "https://apibase.ecomweb.app/api/v1/storefront/stores/<store ref>/cart/items" \
-H "x-storefront-api-key: <storefront secret key>" \
-H "x-session-id: <guest session id>" \
-H "Content-Type: application/json" \
-d '{ "product_id": 123, "variant_id": 456, "quantity": 1 }'

A route that acts for a signed-in shopper also takes the shopper’s access token:

Terminal window
curl "https://apibase.ecomweb.app/api/v1/storefront/stores/<store ref>/customers/orders" \
-H "x-storefront-api-key: <storefront secret key>" \
-H "Authorization: Bearer <shopper access token>"

The storefront secret key replaces the publishable key. It does not replace the shopper’s sign-in.

The API rate-limits requests by the shopper’s address. When your server calls the API with the store’s own storefront secret key, the API takes the shopper’s address from the left-most X-Forwarded-For address your server sends, so the limits count each shopper and not your server. Another store’s key, a publishable key and a key for the shared storefront do not get this. The kit’s backend proxy sends the header for you.

A storefront secret key is never checked against allowed sites. Its IP allow list works like the one on a secret key, described below.

Put the key in the x-api-key header.

Terminal window
curl "https://apibase.ecomweb.app/api/v1/stores/<store ref>/products" \
-H "x-api-key: <secret key>"

The API also accepts the key as Authorization: Bearer <secret key>. When a request carries both headers, x-api-key is read first. A Bearer value that is 100 characters or longer is treated as a signed-in user’s session token, not as a key, so use x-api-key when you can.

Put the key in the x-storefront-api-key header.

Terminal window
curl "https://apibase.ecomweb.app/api/v1/storefront/stores/<store ref>/products/slug/<product slug>" \
-H "x-storefront-api-key: <publishable key>"

Authorization: Bearer <publishable key> also works, and x-storefront-api-key wins when both are present. A Bearer value that looks like a session token (three parts separated by dots) is never read as a key, because shoppers send their access token that way.

A publishable key reaches only the public routes. A browser storefront sends it, and so does a server that reads the catalog.

A publishable key only accepts browser requests from the sites that are allowed for it. Those are your store’s own addresses (your store’s address, your custom domain, http://localhost and http://127.0.0.1 on any port, the http forms only, and the sites of themes you connect from your own server) plus the allowed sites you add to that key. An empty list on the key means only your store’s own addresses, not every site. The API compares the request’s Origin header with that list and answers 403 Origin not allowed for this API key when it does not match. A request with no Origin header, which is what a server sends, skips this check.

A publishable key and a storefront secret key cannot call the Store API. They get a 403 there, whatever their scopes. On a private Storefront API route a publishable key gets 403 STOREFRONT_SECRET_KEY_REQUIRED.

A secret key can only use the scopes you gave it, such as read:products. A read-only key can only hold read scopes. For the full list and which operations need which scope, see the scopes guide.

A secret key stops working when any of these is true:

  • It has passed its expiry date.
  • It is paused, which means Active is off.
  • It is revoked.

The API answers all three the same way: 401 API key is inactive, revoked, or expired. A key it has never seen gets 401 Invalid API key.

Publishable keys and storefront secret keys have no expiry and cannot be paused. They stop working as soon as they are revoked.

Keys are also tied to the person who created them. When that person leaves the store, is removed, is demoted, or hands over ownership, EcomWeb revokes the keys they created. Only a store owner can hold secret keys. As a second check, the API refuses a secret key whose creator no longer qualifies, even if the revoke has not run yet. That request gets 401 API key is no longer valid: the member who created it no longer has permission to manage API keys for this store. After an ownership transfer, the new owner creates new keys.

A key can carry an IP allow list, set in the IP Whitelist field when you create or edit it in Settings › API Keys. Each entry is one address, such as 203.0.113.7, or a range in CIDR form, such as 10.0.0.0/24. IPv4 and IPv6 both work. An empty list allows any address.

The API checks the address that opens the connection to EcomWeb. It ignores X-Forwarded-For and X-Real-IP, so a caller cannot claim another address. A request from an address outside the list gets 403 IP address not whitelisted for this API key. If your server reaches the internet through a proxy or a NAT, list the proxy’s public address.

If a secret key is used on a Storefront API route, the dashboard marks it with a Storefront use badge in Settings › API Keys. The badge means the key is probably shipped in a storefront. Anyone who opens a site can read a key that ships in a browser. Move that code to a publishable key in the browser and a storefront secret key on your server, then revoke the secret key.

Status Message Cause
401 Authentication required: provide JWT in Authorization header or API key in x-api-key header A Store API request with no key
401 API key required in x-storefront-api-key header A Storefront API request with no key
401 Invalid API key The key does not exist
401 API key is inactive, revoked, or expired The key is paused, revoked or past its expiry
401 API key is no longer valid: the member who created it ... The key’s creator no longer holds the right to manage keys
403 Insufficient API key scopes. Required: ... The key lacks a scope the operation needs
403 A readonly API key cannot perform this action. Required: ... A read-only key on an operation that is not a read
403 Storefront keys can only call storefront endpoints A publishable key or a storefront secret key on a Store API route
403 This route needs a storefront secret key, sent from a server (code STOREFRONT_SECRET_KEY_REQUIRED) A publishable key on a private Storefront API route
403 Sign in to manage storefront secret keys; API keys can't (code HUMAN_SESSION_REQUIRED) An API key on the storefront secret key routes, which need a signed-in owner
403 IP address not whitelisted for this API key The caller’s address is not on the key’s IP allow list
403 Origin not allowed for this API key A browser request from a site that is not on the key’s allowed list
403 API key does not have access to this store A Storefront API request with a key that belongs to a different store than the one in the URL

Use the status to decide what to do and the message to find the cause. For the other error bodies and a retry guide, see the errors guide.