Developer docs
Developer docs
Use the API when your own system needs to read what SaleHero knows (stock, orders, invoices, profit) or hand it work (open a return, assign suppliers, place a B2B order). Everything is JSON over HTTPS, and every key belongs to one organization.
The APIs
- Operations API (v1)Open a return with a courier pickup, send a part or a missing product to a customer, read stock and stock changes, and assign suppliers in bulk with the SaleHero /api/v1 endpoints.Read more
- Read API for agents and dashboardsA read-only HTTP API for the data SaleHero reconciles: stock per SKU, the stock ledger, products and cost, orders, returns, invoices, receivables, sales and profit.Read more
- MCP serverConnect Claude Desktop, Claude Code, Cursor or your own agent to SaleHero over the Model Context Protocol with one URL and one API key.Read more
- B2B portal APIFor B2B buyers: place and follow wholesale orders from your own system, and keep a product catalog in sync with a feed link.Read more
- Embeddable returns formPut SaleHero's returns form on your own site with one snippet: customers look up their order, pick the items and open a return without an account.Read more
Which API for which job
| API | Does this job | Key |
|---|---|---|
| /api/v1 | Operations: open a return with courier pickup, read stock and stock changes, assign suppliers in bulk. | sbk_… v1 |
| /api/ai/v1 | Read-only answers for dashboards and AI agents: stock per SKU, orders, returns, invoices, receivables, sales, profit. | sbk_… ai:read |
| /api/mcp | The same data as tools for an MCP client such as Claude Desktop, Claude Code or Cursor. | sbk_… ai:read / agent |
| /api/b2b-portal | For the buyers of a seller who runs the B2B portal: place orders from an ERP and track them. | b2bk_… |
| /returns/<org>/embed | A returns form you embed in your own shop with two lines of HTML. | none (public) |
Base URL
Every path in these docs is relative to the host below. Send JSON in and expect JSON out.
https://salehero.roCreate an API key
- Sign in as an admin and open Settings, API keys.
- Give the key a name you will recognise, for example “ERP integration”. The name is shown wherever the key acts, for instance in the audit log.
- Choose its scope (below) and press Create key.
- Copy the key at once. It is shown a single time; SaleHero keeps only a SHA-256 hash of it and cannot show it again. Lost it? Revoke it and create a new one.
A key looks like sbk_ followed by random characters. Store it in a secret store or an environment variable, never in committed code or a chat. Revoking a key on the same page stops it immediately and touches no other key.
Authentication
Send the key on every request as a bearer token. There is no other way in: a browser sign-in does not apply to these endpoints.
Authorization: Bearer sbk_YOUR_KEYA missing, malformed, unknown or revoked key answers 401. A valid key without the scope the API needs answers 403.
Scopes
A key has exactly one scope, chosen when you create it. In the key form the three scopes carry these labels:
| Scope | Label in Settings | Opens |
|---|---|---|
| v1 | Wrapper API (/api/v1) | The operations API, /api/v1. |
| ai:read | AI agent, read-only (/api/ai/v1) | The read API, /api/ai/v1, and the read tools of the MCP server. Refused by /api/v1. |
| agent | AI agent, full access | Everything an admin colleague can do in the app, plus the read API and MCP. Meant for supervised AI agents; see the MCP page. |
Keys created before scopes existed are v1 keys. Give an integration the narrowest scope that does its job, and one key per integration so you can revoke them separately.
Errors
The operations API (/api/v1) answers failures as JSON with a sentence and, where one applies, a stable code. Switch on the code, not the sentence. A body that fails validation lists the offending fields in issues.
{ "error": "Invalid or revoked API key", "code": "unauthorized" }
{ "error": "Validation failed", "issues": [ { "path": ["take"], "message": "Number must be less than or equal to 500" } ] }The read API (/api/ai/v1) wraps the same information in one envelope:
{ "error": { "code": "sku_not_found", "message": "SKU X is not known to SaleHero" } }| Status | Meaning |
|---|---|
| 400 | The request is invalid: a parameter or the body failed validation. |
| 401 | Missing, malformed, unknown or revoked key. |
| 403 | The key's scope does not open this API, or a route rule denies it. |
| 404 | The thing you asked for does not exist in your organization. |
| 409 | A conflict, for example an Idempotency-Key still in use. |
| 429 | Over the rate limit. Wait for Retry-After seconds. |
| 500 | Something broke on our side. The body carries a short reference; quote it to support. |
Retry 429 and 5xx with a growing delay. Never retry a 4xx unchanged. After a 5xx or a timeout on a write, look up what happened before you send it again.
Rate limits
Each key is limited per minute and per API. The defaults are below; they apply to every key.
| API | Default limit |
|---|---|
| /api/v1 | 120 requests per minute per key |
| /api/ai/v1 | 120 requests per minute per key |
| /api/mcp | 120 requests per minute per key |
| /api/b2b-portal | 120 requests per minute per token |
Responses from /api/v1 carry X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset (seconds until the window reopens). Over the limit you get 429 with a Retry-After header in seconds.
What is recorded
Calls made with a key are attributed to it. The read API and the MCP server write an audit entry per call (key, path or tool, status, duration; for MCP never the arguments). Returns opened through /api/v1 carry the key's name as the opener and are announced in the organization's Slack channel when Slack is connected.