# ShipWave API Documentation

The ShipWave API lets you manage orders, buy shipping labels, track packages, handle returns, and automate fulfillment from your own systems.

**Base URL:** `https://shipwave.app/api/v1`

All requests and responses use JSON. Call the API from your server, never from browser code.

## Quick Start

### 1. Create an API Key

In the ShipWave dashboard, go to **Settings → API Keys**. Only workspace owners can create keys. Create a key with **Shipping API** access. It looks like `sw_live_...` and is shown **only once**, so store it securely. See [Authentication](authentication.md) for access options and scopes.

There are no test keys. See [Testing](testing.md) for how to build an integration without buying labels.

### 2. Make Your First Request

List your connected stores:

```bash
curl https://shipwave.app/api/v1/stores \
  -H "Authorization: Bearer sw_live_abc123..."
```

List your orders:

```typescript
const res = await fetch("https://shipwave.app/api/v1/orders", {
  headers: { Authorization: "Bearer sw_live_abc123..." },
});
const { data, meta } = await res.json();
console.log(`Found ${meta.total} orders`);
```

### 3. Ship an Order

The flow is **get rates → buy the recommended rate**. ShipWave chooses the recommended rate. Only that rate has a `purchaseToken`, and a label can only be bought with that token.

```bash
# 1. Get rates for an order
curl -X POST https://shipwave.app/api/v1/orders/ORDER_ID/rates \
  -H "Authorization: Bearer sw_live_abc123..."

# 2. Buy the label with the recommended rate's purchaseToken
curl -X POST https://shipwave.app/api/v1/orders/ORDER_ID/labels \
  -H "Authorization: Bearer sw_live_abc123..." \
  -H "Content-Type: application/json" \
  -d '{ "purchaseToken": "PURCHASE_TOKEN_FROM_STEP_1" }'
```

```typescript
const headers = {
  Authorization: "Bearer sw_live_abc123...",
  "Content-Type": "application/json",
};

const ratesRes = await fetch(
  `https://shipwave.app/api/v1/orders/${orderId}/rates`,
  { method: "POST", headers },
);
const { data: quote } = await ratesRes.json();

// Single package: the recommended entry in `rates`.
// Several packages: the recommended entry in `aggregatedRates`.
const recommended = quote.isMultiBox
  ? quote.aggregatedRates.find((r) => r.recommended)
  : quote.rates.find((r) => r.recommended);

const labelRes = await fetch(
  `https://shipwave.app/api/v1/orders/${orderId}/labels`,
  {
    method: "POST",
    headers,
    body: JSON.stringify({ purchaseToken: recommended.purchaseToken }),
  },
);
const { data: label } = await labelRes.json();
```

Purchase tokens expire after 15 minutes and only work with the API key that fetched the rates. Before you can get rates, an order needs a warehouse and package details. See [Rates & Labels](rates-and-labels.md) for the requirements, the full response, and multi-package orders.

## Response Format

### Success

```json
{
  "data": { ... }
}
```

### Paginated

List endpoints accept `page` and `limit` (default 50, maximum 100):

```json
{
  "data": [ ... ],
  "meta": {
    "page": 1,
    "limit": 50,
    "total": 250,
    "totalPages": 5
  }
}
```

### Error

```json
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "orderNumber is required",
    "details": {}
  }
}
```

See [Errors](errors.md) for all error codes.

## Retries and Idempotency

- **Creating orders.** Send an `externalId` or an `Idempotency-Key` header. A repeated request returns the original order with `200` instead of creating a duplicate.
- **Buying labels.** Repeating the request with the same purchase token, while the token is still valid, returns the label that was already bought.
- **Rate limit.** 60 requests per minute per key; see [Rate Limiting](rate-limiting.md).

## AI Label Checkout

To let an AI assistant prepare a label for a customer to review and pay for on ShipWave, see [AI label checkout](/docs/ai-label-checkout).

## Support

Email support@shipwave.app with questions about the API.
