# Go live

The checklist. Runs in your test sandbox: nothing is issued, every pass is a test preview. Authenticate with `Authorization: Bearer $PASSBOOK_KEY`. Ids in the examples are placeholders: use the ids your sandbox returns.

A sandbox never issues a real pass, so going live happens in your organization, not here. Work through this list in your sandbox first, then repeat the last two items against the real organization.

## Check your sandbox code

1. Your key comes from `PASSBOOK_KEY`, never from source or a browser. A key sent with browser headers is refused with `403 KEY_IN_BROWSER`.
2. Every create sends an `Idempotency-Key`: see [issue on purchase](https://passbook.mobile/developers/guides/issue-on-purchase).
3. Every update sends `If-Match` and handles `412 VERSION_CONFLICT`: see [update a pass](https://passbook.mobile/developers/guides/update-a-pass).
4. Errors are read by `code`, not by message. Retry only what the [error entry](https://passbook.mobile/developers/errors) marks retryable, with backoff, and honour `Retry-After` on `429`.
5. Webhook handlers verify the raw body, dedupe on event `id` and answer fast: see [react to events](https://passbook.mobile/developers/guides/react-to-events).

## Check what your key can do

**Check which key you use**

```sh
curl -X GET "https://passbook.mobile/api/v1/api-keys/me" \
  -H "Authorization: Bearer $PASSBOOK_KEY"
```

```ts
import { PassBook } from '@passbook/sdk';

const pb = new PassBook({ apiKey: process.env.PASSBOOK_KEY ?? '' });

const key = await pb.apiKeys.retrieveCurrent();

console.log(key.mode, key.scopes);
```

The scopes should be what your code needs and no more.

## Rotate a webhook secret

Rotate before you launch and when a secret leaks. For `overlapHours` (0, 24 or 72, default 24) both secrets sign each request, one `v1=` each. Deploy the new secret inside that window; a verifier that accepts any matching `v1=` never drops an event.

Use your sandbox's capture endpoint: get its `id` first.

```json
{ "eventTypes": ["pass.issued"] }
```

Then rotate. Paste the endpoint `id` into the path.

```json
{ "overlapHours": 24 }
```

The new `secret` is shown once.

## In your real organization

1. Create a Live key with only the scopes you use. See [API keys](https://passbook.mobile/developers/reference/api-keys).
2. Use your own Apple identity for passes you issue, so they carry your name. This is set in the admin, not the API.
3. Make a webhook endpoint with your real URL, and check its first delivery.

## Result

`GET /api-keys/me` on your sandbox shows `mode: test`. The same call with your Live key shows `mode: live`, your scopes and your organization.

## Operations

- [GET /api/v1/api-keys/me](https://passbook.mobile/developers/reference/api-keys#retrieveCurrent): The calling API key: id, name, scopes, organization, mode and use (`pb.apiKeys.retrieveCurrent`)
- [POST /api/v1/webhook-endpoints/capture](https://passbook.mobile/developers/reference/webhook-endpoints#ensureCapture): Get the sandbox's capture endpoint, making it if it has none (`pb.webhookEndpoints.ensureCapture`)
- [POST /api/v1/webhook-endpoints/{id}/secret](https://passbook.mobile/developers/reference/webhook-endpoints#rotateSecret): Rotate the signing secret (`pb.webhookEndpoints.rotateSecret`)

More guides: https://passbook.mobile/developers/guides
