# Update a pass

Change fields, notify. 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.

Change a field on a pass you made, handle a stale version, and end the pass if the order is cancelled. You need a pass: make one with [issue on purchase](https://passbook.mobile/developers/guides/issue-on-purchase) and keep its `id` and `version`.

## Change a field

`PATCH` takes the fields to change under `input`. `notify: true` asks for a push to phones that have the pass.

**Change a field on a pass**

```sh
curl -X PATCH "https://passbook.mobile/api/v1/passes/0193a1b2-7c00-7000-8000-0000000000c1" \
  -H "Authorization: Bearer $PASSBOOK_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "input": {
    "attendee": "Ada Lovelace"
  },
  "notify": true
}'
```

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

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

// notify pushes the change to phones that have the pass.
const pass = await pb.passes.update('0193a1b2-7c00-7000-8000-0000000000c1', {
  input: { attendee: 'Ada Lovelace' },
  notify: true,
});

console.log(pass.version);
```

Paste the pass `id` into the path. The answer is the pass with `version` one higher.

## Guard against a stale write

Send `If-Match` with the `version` you last read. If someone else changed the pass first, the answer is `412 VERSION_CONFLICT`. In the console, add the If-Match chip and set an old version to see it.

Handle it by reading the pass again and retrying with the new `version`. See [VERSION_CONFLICT](https://passbook.mobile/developers/errors/VERSION_CONFLICT).

## Read what changed

**Read what happened to a pass**

```sh
curl -X GET "https://passbook.mobile/api/v1/passes/0193a1b2-7c00-7000-8000-0000000000c1/events" \
  -H "Authorization: Bearer $PASSBOOK_KEY"
```

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

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

for await (const event of pb.passes.activity.list('0193a1b2-7c00-7000-8000-0000000000c1')) {
  console.log(event.kind, event.at);
}
```

The activity list shows the update and its new version, newest first. The pass detail lists every version.

## Void a pass

A voided pass shows as void and scans are refused. The record and its link stay.

**Void a pass**

```sh
curl -X POST "https://passbook.mobile/api/v1/passes/0193a1b2-7c00-7000-8000-0000000000c1/void" \
  -H "Authorization: Bearer $PASSBOOK_KEY"
```

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

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

const pass = await pb.passes.void('0193a1b2-7c00-7000-8000-0000000000c1');

console.log(pass.status);
```

Undo it:

**Undo a void**

```sh
curl -X POST "https://passbook.mobile/api/v1/passes/0193a1b2-7c00-7000-8000-0000000000c1/unvoid" \
  -H "Authorization: Bearer $PASSBOOK_KEY"
```

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

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

const pass = await pb.passes.unvoid('0193a1b2-7c00-7000-8000-0000000000c1');

console.log(pass.status);
```

To end a pass for good, see [pass lifecycle](https://passbook.mobile/developers/guides/pass-lifecycle).

## Result

Open the pass's `downloadUrl` after each call. The preview page shows the new field, and the void state after a void. Nothing is pushed in a sandbox; the preview and the activity list are the proof.

## Operations

- [PATCH /api/v1/passes/{id}](https://passbook.mobile/developers/reference/passes#update): Update a pass (`pb.passes.update`)
- [GET /api/v1/passes/{id}/events](https://passbook.mobile/developers/reference/passes#activity-list): Sync log and activity of a pass, newest first (`pb.passes.activity.list`)
- [POST /api/v1/passes/{id}/void](https://passbook.mobile/developers/reference/passes#void): Void a pass (`pb.passes.void`)
- [POST /api/v1/passes/{id}/unvoid](https://passbook.mobile/developers/reference/passes#unvoid): Unvoid a pass (`pb.passes.unvoid`)
- [GET /api/v1/passes/{id}](https://passbook.mobile/developers/reference/passes#retrieve): Get a pass (`pb.passes.retrieve`)

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