---
name: onesim-partner-api
description: "Integrate a business's backend with the onesim partner API to sell eSIMs and data packages under its own brand, with the TypeScript SDK (@onesim.global/sdk on npm) or over HTTPS: authentication, the catalogue, orders with idempotency and the 202 flow, installing eSIMs, usage and signed webhooks. Use when writing server code against api.onesim.global."
---

# onesim partner API

A JSON API over HTTPS at `https://api.onesim.global/v1` for businesses that sell onesim eSIMs and data packages to their own customers, paid from a partner balance. The contract is the OpenAPI document at https://api.onesim.global/v1/openapi.json, rendered at https://api.onesim.global/docs/; read it for every field and error before writing code. In TypeScript or JavaScript, use the SDK; in any other language, call the API over HTTPS.

## Access

- A partner account with the API enabled is required: apply at https://onesim.global/partners/inquiry. Keys are created in the partner platform under **Developers** and shown once.
- Every request sends `Authorization: Bearer osk_live_…`. Keys belong on servers only: never in an app, a browser or a URL. There is no sandbox; every key buys real eSIMs, starting from an onboarding credit.

## With the TypeScript SDK

`@onesim.global/sdk` (https://www.npmjs.com/package/@onesim.global/sdk, MIT) is the official client: Node.js 20 or later, Deno, Bun and Cloudflare Workers, ES module or CommonJS, no dependencies. Its field names are the API's own.

```sh
npm install @onesim.global/sdk
```

```ts
import OnesimClient from '@onesim.global/sdk';

const onesim = new OnesimClient(); // reads ONESIM_API_KEY, or new OnesimClient({ apiKey })
const { data: packages } = await onesim.packages.list(); // what the partner may buy; prices in cents
const pkg = packages.find((item) => item.id === packageId && item.bundle)!; // bundle is null when not offered

// One key per purchase: make it and store it with the booking before buying.
booking.orderKey ??= crypto.randomUUID();
await saveBooking(booking);
const order = await onesim.orders.createAndPoll(
  { type: 'bundle', package_id: pkg.id, reference: booking.id, expected_amount: pkg.bundle!.amount },
  { idempotencyKey: booking.orderKey }
);
if (order.status === 'completed') {
  // order.esim.activation_code as a QR code, or order.esim.ios_install_url / android_install_url; it installs once, on one device
} else {
  // failed: the amount is back on the balance
}
```

- `orders.createAndPoll` creates the order and polls a `202` until it is final. A failed order resolves with `status: 'failed'` rather than throwing, so check `order.status`. The single steps are `orders.create`, `orders.poll` and `orders.retrieve`; also `orders.listAll`, `esims.retrieve` and `balance.retrieve()`.
- The SDK retries a request that got no answer, a `429` and a `500`, `502`, `503` or `504` with the same `Idempotency-Key`, so one call never buys twice. It never retries `provisioning_failed` (final: buying again needs a new key) or `esims_unavailable` (try later). If the process crashes or the call throws, call again with the same key and body: the same order, charged once.
- Errors: `APIError`, or its subclass for the status (`NotFoundError`, `ConflictError`, `RateLimitError`, …), with `code`, `status` and `requestId`. Act on `error.code` (`price_changed`, `insufficient_balance`, `esim_limit_reached`, …), never on the message, and handle a code you do not know by `status`. `APIConnectionError`: no answer after the retries. `PollTimeoutError`: the order is still pending.
- Webhooks: add an https endpoint under **Developers → Webhooks**, then verify every delivery with the raw body, exactly as received. Parsed and re-serialised JSON has other bytes and fails.

```ts
import { verifyWebhook } from '@onesim.global/sdk';

const event = await verifyWebhook({
  payload: await request.text(), // or the raw Buffer (express.raw), never parsed JSON
  signature: request.headers.get('onesim-signature'),
  secret: process.env.ONESIM_WEBHOOK_SECRET! // the endpoint's whsec_… secret
}); // throws WebhookVerificationError: answer 400 and ignore the delivery
```

## Over HTTPS, in other languages

The SDK is for TypeScript and JavaScript only. In any other language, follow these steps with the reference:

1. Read the catalogue: `GET /v1/packages` gives the packages the partner may buy, how (`esim`, `package`, `bundle`) and at what price, in cents of the account's currency.
2. Buy with `POST /v1/orders` and an `Idempotency-Key` header: a new UUID per purchase, the same on every retry of it. A retry with the same key never buys twice; the same key with a different body is `409 idempotency_conflict`. Pass `expected_amount` to refuse a price that changed.
3. `201` means the order is complete. `202` with `status: "pending"` and a `Location` header means the network has not confirmed yet: poll `GET /v1/orders/{id}` every few seconds until `completed` or `failed` (a failed order is refunded). Retry a timeout or a `5xx` with the same key; `502 provisioning_failed` is final and needs a new key.
4. Hand the eSIM to the customer: its `activation_code` as a QR code, or the `ios_install_url` / `android_install_url`. An eSIM installs once, on one device. A package activates when the device first connects in a covered country.
5. Webhooks: add an https endpoint under **Developers → Webhooks** and verify the `Onesim-Signature` header of every delivery as the reference describes.
6. Respect `429 rate_limited`: wait the `Retry-After` seconds.
