# Check in at the door

Scan and admit. 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 till reads a pass's code and admits the holder. This guide sets the pass's check-in rules and shows the till calls. You need a pass: make one with [issue on purchase](https://passbook.mobile/developers/guides/issue-on-purchase).

## Set the rules

`single` admits a pass once. Paste the pass `id` into the path.

**Set how often a pass admits**

```sh
curl -X PUT "https://passbook.mobile/api/v1/passes/0193a1b2-7c00-7000-8000-0000000000c1/check-in" \
  -H "Authorization: Bearer $PASSBOOK_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "rules": {
    "mode": "single"
  }
}'
```

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

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

await pb.passes.checkInRules.update('0193a1b2-7c00-7000-8000-0000000000c1', { rules: { mode: 'single' } });
```

Read them back with [the rules](https://passbook.mobile/developers/reference/passes#checkInRules-retrieve).

## Find the code

A till reads the code the pass's barcode carries. It is `passJson.barcodes[0].message` in the pass detail; the QR on the pass encodes it.

## Call the till

A till call needs a key bound to a terminal, and names the terminal in `x-passbook-device`. Terminals belong to Scanning in an organization: a sandbox has none. Its key gets `422 DEVICE_REQUIRED` without the header and `404 TERMINAL_NOT_FOUND` with one. Run these with a till key from your organization.

**Check a pass in at the door**

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

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

// A terminal key names its device on every call.
const headers = { 'x-passbook-device': 'door-1' };
const input = { code: 'PB-4F7K-92QX', method: 'camera' as const };

const seen = await pb.terminal.resolve(
  { idempotencyKey: crypto.randomUUID(), input, clientTs: Date.now() },
  { headers },
);
console.log(seen);

const admitted = await pb.terminal.act(
  { idempotencyKey: crypto.randomUUID(), input, clientTs: Date.now(), actionId: 'auto' },
  { headers },
);
console.log(admitted);
```

`scan/resolve` shows what a code would do and records nothing. `scan/actions` with `actionId: "auto"` applies the pass's check-in rule. Every call takes its own `idempotencyKey`, so a retry from a flaky connection is safe.

## Undo a scan

`POST /scan/scans/{scanId}/undo` reverses an admit made by mistake, inside the undo window and only for scans the same key made. See the [terminal reference](https://passbook.mobile/developers/reference/terminal).

## Result

The rules read back as you set them. Open the pass's `downloadUrl`: the test preview shows the pass the till would read.

## Operations

- [PUT /api/v1/passes/{id}/check-in](https://passbook.mobile/developers/reference/passes#checkInRules-update): Set pass check-in rules (`pb.passes.checkInRules.update`)
- [GET /api/v1/passes/{id}/check-in](https://passbook.mobile/developers/reference/passes#checkInRules-retrieve): Pass check-in rules (`pb.passes.checkInRules.retrieve`)
- [POST /api/v1/scan/resolve](https://passbook.mobile/developers/reference/terminal#resolve): Read a code (`pb.terminal.resolve`)
- [POST /api/v1/scan/actions](https://passbook.mobile/developers/reference/terminal#act): Scan and act (`pb.terminal.act`)
- [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
