Skip to content

Create and manage API keys

An API key lets a server, an automation tool or CI read and write your store’s data without anyone signing in. You choose which scopes the key can use and when it expires, and you can revoke it at any time. A key only works for the store that created it.

There are three kinds. A secret key is for servers, scripts and CI, and it is sent in the x-api-key header. A publishable key is for storefront code that runs in the browser, and it can only read public catalog and content. A storefront secret key is for your storefront’s server, and it runs carts, checkout, payments and shopper sign-in. Both storefront keys are sent in the x-storefront-api-key header. In Settings › API Keys, secret keys are in the API keys section, publishable keys are in Publishable keys, and storefront secret keys are in Storefront secret keys. For how requests are authenticated, see the authentication guide.

  1. Go to Settings › API Keys and click Create API Key.
  2. Enter a Key Name, for example the name of the system that will use the key.
  3. Under Key Type, keep Standard, or choose Read only if the system only needs to read data. A read-only key can only have read scopes.
  4. Under Scopes, check each scope the key needs, for example read:products. Checking a group name such as read or write selects the whole group.
  5. Check the Expires At date. A new key expires after 90 days. You can pick another date, or clear the date for a key that must never expire.
  6. Click Create.
  7. In the API Key Created box, click Copy and paste the key into your system’s secret storage, for example a server or CI environment variable.
  8. Click I’ve saved this key.

Under IP Whitelist, enter one IP address and press Enter. Repeat for each address. Both IPv4 and IPv6 addresses work, and so do CIDR ranges such as 10.0.0.0/24. If you leave the list empty, the key accepts requests from any address.

Send the key in the x-api-key header. The key only works for the scopes you chose.

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

The store ref is the part after /store/ in the dashboard’s address bar. With the EcomWeb CLI, put the key in the ECOMWEB_API_KEY variable. The key takes priority over a signed-in session, and the CLI does not write it to disk.

Terminal window
# Read the product list with an API key, for example in CI
ECOMWEB_API_KEY=<secret key> ecomweb products list --store-ref <store ref>
  1. Go to Settings › API Keys.
  2. On the key’s row, open More actions and select Edit.
  3. Change the name, scopes, IP list or expiry date.
  4. To pause the key, turn off Active.
  5. Click Save Changes.

You cannot change the key type after you create the key. To use a different type, create a new key. The Last Used and Requests columns show which keys are still in use. The Revoked and expired view lists keys that no longer work.

  1. Go to Settings › API Keys.
  2. On the key’s row, open More actions and select Revoke.
  3. Click Revoke to confirm.
  1. Go to Settings › API Keys. In the Publishable keys section, click New publishable key.
  2. Enter a Name, for example Production site. Use up to 100 characters.
  3. Optional: add a Description (optional) of up to 500 characters.
  4. Under Allowed sites, enter each site that loads your storefront, for example https://shop.example.com, and press Enter. Your store’s address, your verified domain, connected sites and localhost are always allowed, so leave the list empty if those are enough.
  5. Optional: under Allowed IP addresses (optional), list the addresses that may use the key. Leave it empty to accept any server.
  6. Click Create key.
  7. In the Publishable key created box, click Done. You can copy a publishable key from the page at any time.

Your storefront sends this key in the x-storefront-api-key header. It only reaches public routes. To use it on a website that runs on your own server, see the self-hosted site guide.

  1. Go to Settings › API Keys. In the Storefront secret keys section, click New secret key.
  2. Enter a Name, for example the host that will use it. Add a Description (optional) if you like.
  3. Optional: under Allowed IP addresses (optional), list your server’s addresses.
  4. Click Create key.
  5. In the Secret key created box, copy the key into your server’s environment as ECOMWEB_SECRET_KEY, then click Done.

Only the store owner, signed in, can show a storefront secret key. Click Show key on the key’s row and Hide key to mask it again. Copy key copies the key, and the cell stays masked. Each show or copy is recorded. An API key cannot show a storefront secret key, and neither can an impersonation session, which is read-only.

  1. Go to Settings › API Keys.
  2. On the key’s row, open the menu and select Edit.
  3. Change the Name, the Description (optional), the Allowed IP addresses (optional), or for a publishable key the Allowed sites.
  4. Click Save.

You cannot change a key’s kind. To use another kind, create a new key.

Rotate a key when you change who builds your storefront or when you think it leaked.

  1. Create a new key of the same kind.
  2. Deploy the new key to your site or server.
  3. For a storefront secret key, check the old key’s Last used column to see that nothing still uses it. Publishable keys do not show Last used.
  4. Revoke the old key.
  1. Go to Settings › API Keys.
  2. On the key’s row, open the menu and select Revoke.
  3. Click Revoke to confirm.

A hosted store gets a pair of keys named EcomWeb hosting, one publishable key and one storefront secret key. The page marks them Managed by EcomWeb hosting. EcomWeb creates and replaces them for you, so you cannot edit or revoke them. You can still show and copy them. The API refuses an edit or a revoke with 409 KEY_MANAGED_BY_HOSTING.

Run ecomweb auth login first. Inside your storefront project, create saves the key to .env.local. Use --print to show the key once, for example to set it on a host.

Terminal window
ecomweb storefront key # list the store's keys
ecomweb storefront key create --kind secret --name "<name>" # in the project: saved to .env.local
ecomweb storefront key create --kind secret --name "<name>" --print # show it once
ecomweb storefront key revoke <id> --yes # revoke a key

Do I need an API key to use the EcomWeb CLI on my own computer?

Section titled “Do I need an API key to use the EcomWeb CLI on my own computer?”

No. Run ecomweb auth login and approve the sign-in in your browser. The CLI then uses your own role in each store. API keys are for servers and CI, where no one is there to approve.

EcomWeb does not store keys in a readable form, so you cannot view the key again. Create a new key, update the system that used the old one, then revoke the old key.

A storefront secret key is the exception: the store owner can show it again with Show key under Storefront secret keys, so you do not need to rotate it.

Why did a key change to Revoked on its own?

Section titled “Why did a key change to Revoked on its own?”

A key works with the permissions of the person who created it. When that person leaves the store, is removed from it, loses the right to manage keys or transfers ownership, the keys they created are revoked. The small text under the status gives the reason.

What does the Storefront use label on a key mean?

Section titled “What does the Storefront use label on a key mean?”

The dashboard saw that secret key used from a storefront, where anyone can read it. The platform now refuses secret keys on Storefront API routes. Switch the storefront to a publishable key in the browser and a storefront secret key on its server, then revoke that secret key.

Can I manage storefront keys with an API key or from CI?

Section titled “Can I manage storefront keys with an API key or from CI?”

Storefront secret keys can’t be created, shown, edited or revoked with an API key or from CI. Only the store owner, signed in, can, in the dashboard or after ecomweb auth login. An API key gets 403 HUMAN_SESSION_REQUIRED. An API key with the admin:store scope can still list keys and manage publishable keys.

What do I do if a storefront secret key leaks?

Section titled “What do I do if a storefront secret key leaks?”

Create a new storefront secret key, deploy it, then revoke the leaked one. There is no grace period, so the leaked key stops working as soon as you revoke it.