<!-- Generated from the PSBI Partner API Postman collection. Do not edit by hand. Interactive version: https://apis.psbi.com -->

# Recipe: AutoPilot enrollment with status webhooks

Enroll a new hire into their position and keep your system updated as their background check moves from **review** to **in progress** to **complete**, all without polling.

**You'll need:** an API key, the checklist (position) names or ids for your client, and an HTTPS endpoint that can receive webhooks.

## How it fits together

```
Your system                          PSBI
───────────                          ────
POST /autopilot/enroll ───────────▶  202 Accepted (status: received)
                                     person is matched or created, enrolled, order created
                                     person completes the email invitation
            ◀─────────── webhook     review       information collected, awaiting submission
            ◀─────────── webhook     in_progress  searches running
            ◀─────────── webhook     complete     result: clear | needs_review
            ◀─────────── webhook     complete     report_url: the PDF is ready
```

## 1. Get set up with PSBI

Your implementation contact provides:

- an **API key** for the client account;
- the **checklists** you will enroll into, with their exact names or ids, such as `Caregiver` and `Driver`;
- a **signing secret**, once you've sent them your webhook URL.

Decide on an **`external_id`** scheme. It should be unique per request and should lead back to your record, for example `<your record id>-<attempt>`. Every webhook carries it back to you.

## 2. Verify your key

Run **Step 1: Verify your API key**. A `404 TRANSACTION_NOT_FOUND` means the key works.

## 3. Build the webhook receiver first

Build it before you enroll anyone, so the first events aren't missed. Your endpoint should:

1. **Verify `X-P51-Signature`.** It is an HMAC-SHA256 of the raw body with your signing secret, and **Status Webhooks** has code for it.
2. **Return 2xx quickly**, within 30 seconds. Queue the work.
3. **Look the record up by `external_id`.**
4. **Apply the update idempotently.** Retries can repeat an event, and order isn't guaranteed.

## 4. Enroll

Run **Step 2: Enroll the new hire**. The request is asynchronous and returns `202` with your `external_id`:

```json
{
  "success": true,
  "transaction_id": 1234,
  "external_id": "HR-2026-001234",
  "status": "received",
  "message": "Enrollment request received and queued for processing",
  "received_at": "2026-09-15T14:02:11.000000Z"
}
```

Store the mapping from `external_id` to your record. If you get `409 DUPLICATE_TRANSACTION`, that `external_id` is already in use; don't reuse ids across attempts.

## 5. Confirm it processed (optional)

Run **Step 3: Check the enrollment** about a minute later.

- **`transaction.status: "processed"` with a `consumer_transaction`.** An order exists and webhooks will follow.
- **`transaction.status: "failed"`.** `error_message` says why. Fix the problem and enroll again with a **new** `external_id`.

## 6. Handle the status webhooks

| `status` | `result` | Suggested state in your system |
|---|---|---|
| `review` | | Awaiting submission |
| `in_progress` | | Screening in progress |
| `complete` | `clear` | Screening complete: clear |
| `complete` | `needs_review` | Screening complete: client review needed |

On `consumer.transaction.report_generated`, download `report_url` and attach the PDF to the person's record.

Two things to know:

- **`review` happens before searches run.** It means the order is ready to submit. The outcome of the searches only arrives on `complete`.
- **`needs_review` is not a decision.** It means a person at the client needs to look at a result in PSBI. Any adverse action runs through PSBI's FCRA workflow, not through the API.

## 7. Test it end to end

1. Point the webhook URL at a request inspector, such as webhook.site, or your staging receiver.
2. Enroll a test person with **your own email address** on the `email_onboarding` path.
3. Complete the invitation email. You should receive **review**, then **in progress**.
4. Your implementation contact can take a test order through to **complete** and **report ready**.
5. Check signature verification against the real deliveries, not just the examples here.

## Going live checklist

- [ ] Production API key stored server-side.
- [ ] Webhook URL registered, and signing secret stored.
- [ ] Signature verified on every request, and mismatches rejected.
- [ ] Receiver acknowledges within 30 seconds and tolerates duplicates.
- [ ] `external_id` is unique per request.
- [ ] Reports downloaded from `report_url` and stored securely.
- [ ] Failed enrollments surfaced to a person (step 5).

## Requests used in this recipe

### Step 1: Verify your API key

```http
GET https://app.psbi.com/api/v1/partners/transactions/test-auth-check
X-API-Key: <your API key>
Accept: application/json
```

A working key returns `404 TRANSACTION_NOT_FOUND`. Any `401` means the key or header is wrong.

### Step 2: Enroll the new hire

```http
POST https://app.psbi.com/api/v1/partners/autopilot/enroll
X-API-Key: <your API key>
Content-Type: application/json
Accept: application/json
```

Enroll into the position on the `email_onboarding` path. The person receives an invitation, and the order is submitted once they finish it.

Set `external_id` to something that leads back to your record. The test script saves it for Step 3.

Every field and path is documented under **AutoPilot API → Enroll Consumer**.

**Request body**

```json
{
  "external_id": "HR-1789500000",
  "consumer": {
    "first_name": "Jane",
    "last_name": "Doe",
    "email": "you+psbi-test@example.com",
    "phone": "555-123-4567",
    "state": "TX"
  },
  "checklist_code": "Caregiver",
  "enrollment_path": "email_onboarding",
  "metadata": {
    "requisition_id": "REQ-2231"
  }
}
```

**Example response: Accepted (async)** (202 Accepted)

```json
{
  "success": true,
  "transaction_id": 1234,
  "external_id": "HR-2026-001234",
  "status": "received",
  "message": "Enrollment request received and queued for processing",
  "received_at": "2026-09-15T14:02:11.000000Z"
}
```

### Step 3: Check the enrollment

```http
GET https://app.psbi.com/api/v1/partners/autopilot/enrollment/{external_id}
X-API-Key: <your API key>
Accept: application/json
```

Confirms the request was `processed` and an order exists. A `failed` request carries `error_message`.

**Example response: Processed** (200 OK)

```json
{
  "success": true,
  "transaction": {
    "id": 1234,
    "external_id": "HR-2026-001234",
    "type": "autopilot_enroll",
    "status": "processed",
    "received_at": "2026-09-15T14:02:11.000000Z",
    "processed_at": "2026-09-15T14:02:43.000000Z",
    "error_message": null
  },
  "enrollment": {
    "id": 108,
    "consumer_id": 54321,
    "consumer_created": true,
    "search_count": 0,
    "pending_requirements": true
  },
  "consumer_transaction": {
    "id": 98765,
    "status": "draft",
    "submitted_at": null,
    "consumer": {
      "id": 54321,
      "name": "John Doe"
    }
  }
}
```

**Example response: Failed** (200 OK)

```json
{
  "success": true,
  "transaction": {
    "id": 1299,
    "external_id": "HR-2026-001299",
    "type": "autopilot_enroll",
    "status": "failed",
    "received_at": "2026-09-15T14:02:11.000000Z",
    "processed_at": "2026-09-15T14:02:43.000000Z",
    "error_message": "Enrollment created but transaction failed: No requirements found for this checklist"
  }
}
```

---

Full reference, including every field, error code and webhook body: [partner-api.md](./partner-api.md)
