You need to be the owner of a TradeCatalog workspace with an active subscription, a free trial or a pilot account. Demo workspaces can’t use the API.
1. Make an API keyLink to this section#
- Open your workspace and go to Settings → API.
- Give the key a name you’ll recognise later, like “Sage stock sync”.
- Choose Read only to look things up, or Read & write to also update products, customers and orders.
- Choose Create key and copy it. It starts with
tc_live_.
Copy it now
We only show a key once, and we only keep a hash of it. If you lose it, revoke it and make a new one.
Put the key in an environment variable so it stays out of your code:
export TRADECATALOG_API_KEY="tc_live_…"
2. Check the key worksLink to this section#
curl https://tradecatalog.app/api/v1/workspace \
-H "Authorization: Bearer $TRADECATALOG_API_KEY"
{
"data": {
"id": "0b6c1f5e-6f7a-4a57-9a0c-2f4d4c1e8a11",
"slug": "northgate",
"name": "Northgate Fixings",
"currency": "GBP",
"timezone": "Europe/London",
"taxLabel": "ex VAT",
"key": { "name": "Sage stock sync", "scope": "write" }
}
}
3. Search productsLink to this section#
curl "https://tradecatalog.app/api/v1/products?q=hinge&limit=2" \
-H "Authorization: Bearer $TRADECATALOG_API_KEY"
Money is always in minor units of the workspace currency, so 1850 is £18.50. See Conventions.
4. Get a customer’s priceLink to this section#
Pass a customer’s account code (or id) and a SKU:
curl "https://tradecatalog.app/api/v1/prices?customer=OAK01&sku=HX-8510&qty=10" \
-H "Authorization: Bearer $TRADECATALOG_API_KEY"
{
"data": {
"customer": {
"id": "7d2e4f0a-1b3c-4d5e-8f90-a1b2c3d4e5f6",
"accountCode": "OAK01",
"name": "Oakfield Joinery"
},
"sku": "HX-8510",
"name": "Hex bolt M10 x 50 zinc",
"qty": 10,
"unit": 1573,
"line": 15730,
"list": 1850,
"discountBp": 1500,
"source": "brand",
"label": "Brand discount −15%"
},
"currency": "GBP"
}
How prices are worked out explains source and label.
5. Create or update a productLink to this section#
This needs a Read & write key.
curl -X PUT https://tradecatalog.app/api/v1/products \
-H "Authorization: Bearer $TRADECATALOG_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"products": [
{
"sku": "HX-8512",
"name": "Hex bolt M12 x 50 zinc",
"listPrice": 2240,
"unitLabel": "Box of 100",
"brand": "Northgate",
"category": "Bolts"
}
]
}'
{
"data": {
"created": 1,
"updated": 0,
"priceChanges": 0,
"priceChangeId": null,
"unknownCustomers": []
}
}
New products go live at their list price straight away. If you send a different price for a product that already has one, the price doesn’t change yet. It goes into a draft price change that you review and publish in the app. See Products.
The same in JavaScriptLink to this section#
const api = (path, init = {}) =>
fetch(`https://tradecatalog.app/api/v1${path}`, {
...init,
headers: {
Authorization: `Bearer ${process.env.TRADECATALOG_API_KEY}`,
'Content-Type': 'application/json',
...init.headers,
},
}).then(async (res) => {
const body = await res.json()
if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`)
return body
})
const { data: workspace } = await api('/workspace')
const { data: price } = await api('/prices?customer=OAK01&sku=HX-8510&qty=10')
console.log(`${workspace.name}: ${price.name} is ${price.unit / 100} each`)
Next stepsLink to this section#
- Authentication: scopes, revoking keys, keeping them safe.
- Errors: every error code and how to retry.
- Sync with your ERP: a complete nightly sync and order poller.
- OpenAPI: generate a typed client.