<!-- Source: https://www.orderkraft.com/docs/developers/api/ -->

# The Orderkraft API

The Orderkraft API lets your own tools read and change your production data. Pull manufacturing orders into a reporting dashboard, keep materials in sync with your ERP, or set lead times from a spreadsheet instead of clicking through every variant.

It's a JSON API over HTTPS. Every request is limited to your own shop, and to what the API key you send is allowed to do. The same API powers [Orderkraft's MCP server](/docs/developers/connect-an-ai-assistant/), so an AI assistant sees exactly the data your scripts do.

This page covers how the API works in general. The [API reference](/docs/developers/api-reference/) lists every endpoint and what it returns.

## Create an API key

API keys live in Orderkraft under **Settings → API keys**. Click **Create API key** and fill in:

- **Name.** Something you'll recognise later, like the tool that uses it. "Metabase" beats "Key 3".
- **Description.** Optional. A note for your team about where the key is used.
- **Permissions.** *Read* lets the key see products, materials, lead times, bills of materials, manufacturing orders and work orders. *Write* lets it create and change materials, production settings, lead times and bills of materials.
- **Expiration.** 7 days, 30 days, 3 months, 6 months, 1 year, or no expiration. The default is 3 months, so a key someone forgot about doesn't stay open forever.

Most integrations that write also need *Read*, because they look something up before they change it. A key with only *Write* can update a lead time if it already knows the ID, but it can't find that ID on its own.

Orderkraft shows the key once, right after you create it. It starts with `ok_live_`. Copy it into a password manager or your tool's secret settings straight away. Orderkraft only keeps a fingerprint of the key, so nobody can show it to you again, us included. Lost it? Revoke it and create a new one.

### Revoke a key

Open the key from the list and click **Revoke**. Any tool using it loses access right away, and a revoked key can't be switched back on.

### See what a key does

Click a key in the list to open its page. Under **API requests** you'll find everything the key changed, newest first:

- **Request.** For the API, the method and path, like `PATCH /api/v1/materials/812`. For an AI assistant, the name of the tool it called, like `update_lead_time`. Below it, the record that was touched, like *Material #812*.
- **Outcome.** *Succeeded*, or *Failed* with the HTTP status. A `403` here means the key tried something its permissions don't allow, and a `422` means the change didn't pass validation.
- **Type.** *API* for requests to the API, *MCP* for an AI assistant's tool calls.
- **Changes.** Which fields changed, like `sku` or `production_time_max`. Only the names are kept, never the values.

Search by request or tool name, or filter on the type, to find one change among many.

Reads work differently. A dashboard polling every few seconds would bury the changes you care about, so `GET` requests to the API aren't listed one by one. They're counted per day, and the **History** section on the key's page shows how many read requests it made in the last 30 days. No reads at all usually means nothing uses the key anymore, so it's a good candidate to revoke. Tool calls from an AI assistant are listed individually, reads included, so you can follow what it looked up as well as what it changed.

Requests with a wrong, expired or revoked key aren't logged, since there's no key to log them against. Orderkraft keeps the log, and the read counts, for 90 days. It also stores the IP address each request came from, encrypted.

Give each tool its own key, with only the access it needs. When you stop using a tool, or someone who had a key leaves, you revoke one key and nothing else breaks.

## Make a request

Send the API key as a bearer token in the `Authorization` header. The base URL is `https://orderkraft.app/api/v1`.

```sh
curl https://orderkraft.app/api/v1/manufacturing_orders \
  -H "Authorization: Bearer ok_live_..."
```

The same request in JavaScript:

```js
const ORDERKRAFT_API_KEY = process.env.ORDERKRAFT_API_KEY;

const response = await fetch("https://orderkraft.app/api/v1/manufacturing_orders", {
  headers: { Authorization: `Bearer ${ORDERKRAFT_API_KEY}` },
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`Orderkraft API error ${response.status}: ${error}`);
}

const { data, pagination } = await response.json();
```

Keep the key on a server or in a script. Never put it in a storefront theme or anything else that runs in a customer's browser, because anyone could read it there.

## Requests and responses

Every response is a JSON object with a `data` key. For a single record, `data` is that record. For a list, it's an array, and a `pagination` object comes along with it.

Keys are camelCase: `productionStrategy`, `shipBy`, `billOfMaterial`. Request bodies use the same keys as responses, as a flat JSON object. Send them with a `Content-Type: application/json` header.

```sh
curl -X PATCH https://orderkraft.app/api/v1/materials/812 \
  -H "Authorization: Bearer ok_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "sku": "OAK-PLANK-2M", "unitOfMeasure": "pc" }'
```

A few more conventions:

- IDs are Orderkraft's own numbers. Products and variants also carry a `shopifyId`, their Shopify GID like `gid://shopify/Product/8912374651`, so you can match them to Shopify.
- Timestamps are ISO 8601 with a time zone, like `2026-11-24T09:41:00.000+01:00`. Dates, like `shipBy`, are `YYYY-MM-DD`.
- Fields that don't apply are `null` rather than left out. A build-to-stock manufacturing order has `"salesOrder": null`, and a variant without a lead time has `"leadTime": null`.
- Responses are never cached. You always get the data as it is right now.

## Pagination

List endpoints return 20 records per page by default. Ask for up to 100 with `limit`, and pick a page with `page`, starting at 1.

```sh
curl "https://orderkraft.app/api/v1/products?limit=100&page=2" \
  -H "Authorization: Bearer ok_live_..."
```

The `pagination` object tells you where you are:

```json
{
  "data": ["..."],
  "pagination": {
    "page": 2,
    "pages": 4,
    "count": 342,
    "limit": 100,
    "nextPage": 3
  }
}
```

`count` is the total number of records across all pages. `nextPage` is `null` on the last page, which makes looping over everything simple:

```js
const fetchAll = async (path) => {
  const records = [];
  let page = 1;

  while (page) {
    const response = await fetch(`https://orderkraft.app/api/v1/${path}?limit=100&page=${page}`, {
      headers: { Authorization: `Bearer ${process.env.ORDERKRAFT_API_KEY}` },
    });
    const { data, pagination } = await response.json();

    records.push(...data);
    page = pagination.nextPage;
  }

  return records;
};

const materials = await fetchAll("materials");
```

## Search and filters

Most list endpoints take a `query` param that searches the fields you'd expect: names, SKUs, barcodes, or order numbers. Searches match anywhere in the field and ignore case, so `query=oak` finds "Oak plank" and "White oak veneer".

Manufacturing orders and work orders also take filters, written as `filters[name]=value`:

```sh
curl "https://orderkraft.app/api/v1/manufacturing_orders?filters[urgency]=overdue" \
  -H "Authorization: Bearer ok_live_..."
```

The [API reference](/docs/developers/api-reference/) lists which searches and filters each endpoint supports.

Archived products, variants and materials are left out of lists unless you add `includeArchived=true`.

## Errors

When something goes wrong, `data` is `null` and `error` says why in a sentence:

```json
{
  "data": null,
  "error": "This API key isn't allowed to do that"
}
```

| Status | What happened |
| --- | --- |
| `400 Bad Request` | A required param is missing, like `materialId` when adding to a bill of materials. |
| `401 Unauthorized` | The API key is missing, wrong, revoked or expired. |
| `403 Forbidden` | The key is valid but doesn't have the permission this request needs. Reading needs *Read*; creating, changing and removing need *Write*. |
| `404 Not Found` | The record doesn't exist, or belongs to another shop. |
| `422 Unprocessable Content` | The change didn't pass validation. See below. |
| `429 Too Many Requests` | You hit the rate limit. |

A `422` also tells you which fields were wrong, keyed the same way as the request:

```json
{
  "data": null,
  "error": "Production time max must be greater than or equal to 3",
  "errors": {
    "productionTimeMax": ["must be greater than or equal to 3"]
  }
}
```

## Rate limits

Each shop can make 300 requests per minute. That's shared between all of its API keys and any AI assistant connected over MCP, so one busy integration can slow down another.

Go over it and you get a `429` with a `Retry-After` header saying how many seconds to wait. Wait that long, then try again. If you regularly hit the limit, fetch 100 records per page instead of the default 20. That alone cuts most syncs to a fifth of the requests.

Requests with a missing or wrong key count too, per IP address. A script stuck retrying with a revoked key will lock itself out for a minute.
