User docs / Catalog

Use the API from the command line

Import and export products from a terminal with a store API token and curl.

In the dashboard: A store, Admin, API access

What it is for

A catalog kept in a spreadsheet or made by another system changes often. Sending the file from a terminal, or from a script that runs every night, saves opening the dashboard each time. The commands use curl, which comes with macOS, Linux and Windows 10 and later, so there is nothing to install.

A command proves it may act on your store with a token. Each token works for one store only, with the permissions you pick, so a script that imports products cannot read orders or change settings.

Create a token

  1. Open the store, then Admin, then API access under Developers.
  2. Under Create a token, name it after what will use it, for example "product import on my laptop", so you know later which one to revoke.
  3. Pick its permissions. View products and Bulk import products are ticked: that is what the import and export commands need. View orders and customers lets a command read orders. View the summary, traffic, products, search terms and reports and View usage and plan let a script read the Observability numbers.
  4. Choose when it expires, or Never, and press Create token.
  5. Copy the token now and keep it somewhere safe, like a password manager. It is shown only this once: the store keeps only a fingerprint of it.

Store owners and admins can create tokens. A teammate can give a token only permissions they have themselves, and a token can never manage the team or other tokens.

The commands

API access lists every command with your store's address filled in, for macOS and Linux or for Windows PowerShell. Copy them from there. They all start with the same address, https://dash.commernauts.com/api/v1/stores/<store id>/admin, which checks the token and passes the call to your store.

First keep the token in the terminal window, so the other commands can use it without it being typed into each one. Right after you create a token, this command on the page already holds it.

export COMMERNAUTS_TOKEN='cnt_...'

In Windows PowerShell:

$env:COMMERNAUTS_TOKEN = 'cnt_...'

The file is the same CSV as Products, Import reads. Run the commands in the folder that holds products.csv.

Check a file without saving it

Before an import changes your catalog, check what it would do. Each row answers would_create, would_update, unchanged or error with the reason. Nothing is saved.

curl -sS -X POST "https://dash.commernauts.com/api/v1/stores/<store id>/admin/api/owner/products/bulk?dry_run=1" -H "Authorization: Bearer $COMMERNAUTS_TOKEN" -H "Content-Type: text/csv" --data-binary "@products.csv"

The answer starts with a summary, then one entry per product:

{
  "dry_run": true,
  "summary": { "rows": 2, "created": 1, "updated": 1, "unchanged": 0, "failed": 0 },
  "results": [
    { "index": 0, "handle": "stoneware-mug", "sku": null, "status": "would_create" },
    { "index": 1, "handle": "bud-vase", "sku": "VASE-BUD", "status": "would_update", "product_id": "p_..." }
  ]
}

A row with a problem says which column is wrong, for example "status": "error", "errors": { "price_minor": "a whole number of minor units above 0" }. Fix the file and check again.

Import a file

The same command without dry_run saves the file. Rows are matched to existing products by handle, then by SKU, so sending the same file twice changes nothing the second time.

curl -sS -X POST "https://dash.commernauts.com/api/v1/stores/<store id>/admin/api/owner/products/bulk" -H "Authorization: Bearer $COMMERNAUTS_TOKEN" -H "Content-Type: text/csv" --data-binary "@products.csv"

Each row answers created, updated or unchanged with its product id. For a file of up to 100 products, image_url pictures are fetched and stored in the same call, and the row says "image": "stored".

Follow a large import

A file with more than 100 products (up to 20,000) runs in the background, so it is not cut off by the time a single request may take. The import then answers with a job instead of the rows:

{ "job": { "id": "bj_...", "status": "queued", "total": 450, "processed": 0, ... } }

Ask for its progress with the job id until status is done. Background imports do not fetch image_url pictures; import those rows in files of up to 100.

curl -sS "https://dash.commernauts.com/api/v1/stores/<store id>/admin/api/owner/bulk-jobs/bj_..." -H "Authorization: Bearer $COMMERNAUTS_TOKEN"
{ "job": { "id": "bj_...", "status": "done", "total": 450, "processed": 450, "summary": { "created": 448, "updated": 2, "unchanged": 0, "failed": 0 }, ... } }

Export products

The export saves every product to products.csv in the columns the import reads, so you can edit it in a spreadsheet and send it back. Sending it back unchanged reports 0 created and 0 updated.

curl -sS "https://dash.commernauts.com/api/v1/stores/<store id>/admin/api/owner/products/export?format=csv" -H "Authorization: Bearer $COMMERNAUTS_TOKEN" -o products.csv

One export holds up to 2,000 products. A larger catalog is exported in the background from Products, Import in the dashboard.

List products

To see what is in the store from the terminal, list the newest 100 products with their id, title, price, stock and status:

curl -sS "https://dash.commernauts.com/api/v1/stores/<store id>/admin/api/owner/products?limit=100" -H "Authorization: Bearer $COMMERNAUTS_TOKEN"

On Windows

In PowerShell, curl is a different program, so the commands call curl.exe and read the token from $env:COMMERNAUTS_TOKEN. Choose Windows (PowerShell) on API access to get them written that way.

When a command is refused

AnswerWhat it means
401 invalid_tokenThe token is wrong, revoked or expired. Create a new one.
403 action_not_grantedThe token lacks the permission this command needs, for example Bulk import products for an import. Create a token with it.
403 not_store_ownerThe token belongs to another store. Check the store id in the address.
429 rate_limitedToo many calls in a short time. Wait the seconds the answer names and run it again.

Revoke a token

Revoke a token you no longer use, or one that may have been seen by someone else. Under Admin, API access, press Revoke next to it. The next call with it is refused; nothing else changes.

The list shows when each token was last used, which helps find the ones nothing uses any more. Every call made with a token is recorded with the token's name, and creating and revoking tokens is recorded with who did it.