# PSBI Platform Partner API

Set up and manage PSBI client accounts from inside your platform: create an account for each customer, sign their people in, organize them into locations or divisions, and configure the screening they run.

This guide is for **platform partners**: software that offers PSBI screening to many of its own customers through one integration. Each of your customers is a PSBI client account. Your API key reaches every account your platform created, and no other.

Ordering, enrollment and status webhooks are covered in the [PSBI Partner API reference](https://psbi.com/developers/partner-api.md). This guide covers account setup and management.

| Part | What it does |
|---|---|
| **Accounts** | Create a client account with its users, optionally with screening already configured. |
| **Sign-in links** | Send a user straight into PSBI from your platform, with no password to type. |
| **Organizations** | Add locations, divisions or member companies under an account, and route orders to them. |
| **Products** | List what an account can order. |
| **Checklists and tags** | Create and maintain the screening an account runs for each position. |

PSBI turns each part on for your platform. A call to a part that is not on returns `403 CAPABILITY_NOT_ALLOWED`. Ask your PSBI implementation contact which parts your agreement covers.

## Basics

### Base URL

```
https://app.psbi.com/api/v1/partners/{platform}
```

`{platform}` is your platform code, issued with your API key.

### Authentication

Send your API key on every request:

```
X-API-Key: your-api-key
```

`Authorization: Bearer your-api-key` is also accepted. Keep the key server-side: it reaches every account your platform created.

### Requests and responses

Send JSON with `Content-Type: application/json` and `Accept: application/json`.

Every response has a boolean `success`. A failure adds an `error` object:

```json
{
  "success": false,
  "error": {
    "code": "VALIDATION_FAILED",
    "message": "The name has already been taken.",
    "details": { "name": ["The name has already been taken."] }
  }
}
```

### Which accounts you can reach

Every path under `/clients/{clientId}` acts on one account. You can reach only accounts your platform created. Any other id returns `404 CLIENT_NOT_FOUND`, the same answer as an id that does not exist.

Store the `client_id` PSBI returns when you create an account. It is the id every later call uses.

## Accounts

### Create an account

```
POST /clients
```

```json
{
  "company_name": "Example Logistics LLC",
  "state": "KS",
  "city": "Wichita",
  "zip": "67202",
  "street": "100 Main St",
  "phone": "3165551234",
  "external_id": "emp-1042",
  "billing_email": "ap@example.com",
  "send_email": true,
  "users": [
    { "first_name": "Dana", "last_name": "Ruiz", "email": "dana@example.com" },
    { "first_name": "Lee", "last_name": "Park", "email": "lee@example.com" }
  ],
  "checklists": [
    { "name": "Drivers", "services": ["mvr", "base", "sanc"] }
  ]
}
```

| Field | Required | Notes |
|---|---|---|
| `company_name` | Yes | The account's name. |
| `state` | Yes | Two-letter state code. |
| `users` | Yes | At least one. The first user is the account owner. |
| `city`, `zip`, `street`, `phone` | No | Left blank when not sent. |
| `external_id` | No | **Your** id for this customer. Orders that carry it are routed to this account. Unique within your platform. |
| `billing_email` | No | Where invoices go. Defaults to the first user's email. |
| `send_email` | No | `true`: PSBI emails each new user a welcome message with a temporary password. `false` (default): the response returns the temporary passwords for you to deliver. |
| `checklists` | No | Screening to set up on the account now. See [Checklists in the create call](#checklists-in-the-create-call). |

**Roles.** The first user gets `Client - Admin` and `Client - Finance` (account owner, receives invoices). Every later user gets `Client - Basic`. To override this, send `roles` on a user, for example `"roles": ["Client - Admin"]`.

Response `201`:

```json
{
  "success": true,
  "client_id": 512,
  "user_id": 840,
  "status": "active",
  "login_url": "https://app.psbi.com/login",
  "auto_login_url": "https://app.psbi.com/auth/link/…",
  "users": [
    { "user_id": 840, "email": "dana@example.com", "existing": false },
    { "user_id": 841, "email": "lee@example.com", "existing": false }
  ],
  "welcome_email_sent": [840, 841],
  "checklists": [ { "checklist_id": 301, "name": "Drivers", "items": 4 } ]
}
```

- `credentials` replaces `welcome_email_sent` when `send_email` is `false`. Each entry carries a `temporary_password`, which the user changes at first sign-in.
- `auto_login_url` is present only when the account can sign in right away. See [Sign-in links](#sign-in-links).
- `unresolved_services` and `unresolved_products` appear only when part of `checklists` could not be set up.

### People who already use PSBI

One person has one PSBI login, however many accounts they work with. When a `users` email already has a login, that person is **added** to the new account, not refused. They keep:

- their password, so they get no `credentials` entry and no welcome email;
- their roles, so `roles` is ignored for them;
- their other accounts, which nothing removes them from.

`users` in the response marks them `"existing": true`. Tell them to sign in with the password they already have.

An email that belongs to a PSBI staff account returns `422 USER_NOT_ATTACHABLE`, and nothing is created.

**Is it really a new account?** If your customer is part of a company that already has a PSBI account, consider adding it as an [organization](#organizations) under that account instead. The same admin then manages both from one login.

### Checklists in the create call

`checklists` sets up screening while the account is created, so its owner does not start from an empty account. Each checklist names its services in either of two forms:

```json
"checklists": [
  { "name": "Drivers", "services": ["mvr", "base", "sanc"] },
  { "name": "Office", "items": [ { "service": "base" }, { "product_id": 25, "name": "OIG" } ] }
]
```

- `services` is a list of service codes. One code can cover several products: `sanc` sets up both OIG and SAM.gov.
- `items` is an ordered list. Each item is a service code or a `product_id`. Send the product's `name` with an id and PSBI checks that they match.

Anything that cannot be resolved is **skipped, not refused**, and reported in `unresolved_services` or `unresolved_products`, so the signup still succeeds. To change screening after the account exists, use [Checklists and tags](#checklists-and-tags), which refuse what they cannot resolve.

| Code | Covers |
|---|---|
| `base` | National criminal search |
| `county` | County criminal search |
| `mvr` | Motor vehicle record |
| `emp` | Employment verification |
| `edu` | Education verification |
| `sanc` | Exclusion lists (OIG and SAM.gov) |
| `mon` | Ongoing sanctions monitoring |

## Sign-in links

A sign-in link drops a user into PSBI already signed in, so they never type a password on your page. The create call returns one as `auto_login_url`. To get a fresh one later:

```
POST /clients/{clientId}/login-link
```

```json
{ "email": "dana@example.com" }
```

`email` is optional and defaults to the account owner. The response is `{ "success": true, "user_id": 840, "auto_login_url": "…" }`.

- A link works **once** and expires after **15 minutes**. Mint one when the user clicks, not ahead of time.
- Minting a new link expires the user's previous unused one.
- Links are issued only for a user who belongs to **exactly one** PSBI account, the one your platform created. Someone who also works with another account signs in with their own password, and the request returns `403 LOGIN_LINK_NOT_ALLOWED`.
- An account waiting for PSBI to activate it cannot sign in yet: `409 CLIENT_NOT_OPERABLE`.

## Organizations

An organization is a location, division or member company inside an account. Orders, people and checklists can belong to one. Every account starts with one organization.

| Method | Path | |
|---|---|---|
| `GET` | `/clients/{clientId}/organizations` | List all, inactive included |
| `POST` | `/clients/{clientId}/organizations` | Create |
| `PATCH` | `/clients/{clientId}/organizations/{organizationId}` | Change the fields you send. `users` adds people. |
| `DELETE` | `/clients/{clientId}/organizations/{organizationId}` | Deactivate. `PATCH` with `"status": "active"` restores it. |

```json
POST /clients/512/organizations
{
  "name": "Example Logistics: Topeka",
  "external_id": "emp-2210",
  "code": "TOP",
  "city": "Topeka",
  "state": "KS",
  "contact_name": "Sam Lee",
  "contact_email": "sam@example.com",
  "users": [
    { "first_name": "Sam", "last_name": "Lee", "email": "sam@example.com" }
  ],
  "send_email": true
}
```

| Field | Notes |
|---|---|
| `name` | Required on create. |
| `external_id` | **Your** id for this location or member company. See [Routing orders](#routing-orders-to-an-organization). Send `null` to clear it. |
| `code` | Short code, unique within the account. |
| `parent_organization_id` | Nest under another organization of the same account. |
| `street`, `unit`, `city`, `state`, `zip`, `country`, `phone`, `contact_name`, `contact_email` | Optional details. |
| `users` | People to give this organization, in the same shape as on account create. New users get `Client - Basic` unless `roles` says otherwise. |
| `status` | `PATCH` only: `active` or `inactive`. |

The response returns the `organization`. When `users` was sent, it also returns `users` and `credentials` (or `welcome_email_sent`) as on account create.

### Routing orders to an organization

Give an organization an `external_id`, and orders carrying that id land on its account, recorded against that organization. It is the same identifier your orders already send for an account. PSBI first looks for an account with the id, then an organization.

Within your platform, one id names exactly one account or organization. Reusing one returns `409 EXTERNAL_ID_IN_USE`.

### People and organization access

A user who belongs to an account with no organization assigned sees the **whole** account. Assigning an organization narrows them to it. So:

- Someone who already sees the whole account is left that way. They come back as `"access": "client_wide"`.
- Anyone else is added to the account if needed and given this organization: `"access": "organization"`.

This endpoint adds people and never removes them.

An account keeps at least one active organization: deactivating its last returns `409 LAST_ACTIVE_ORGANIZATION`. An organization cannot be nested under itself or one of its children: `422 ORGANIZATION_CYCLE`.

## Products

```
GET /clients/{clientId}/products
```

```json
{
  "success": true,
  "products": [
    { "product_id": 21, "name": "MVR", "service": "mvr", "category": "Driving", "type": "mvr" },
    { "product_id": 25, "name": "OIG", "service": "sanc", "category": "Sanctions", "type": "sanctions" }
  ]
}
```

These are the products this account can order. `service` is the product's service code, where it has one. Prices are not included; they come from your PSBI agreement. Read the list per account, because accounts can be limited to a curated set.

## Checklists and tags

A **checklist** is the screening a position requires. Enrolling a person into it orders everything on it and keeps it current. A **tag** adds requirements on top of a checklist for the people who carry it, for example "CDL driver". Both take the same calls. A checklist lists its screening under `items`; a tag lists it under `requirements`.

| Method | Path | |
|---|---|---|
| `GET` | `/clients/{clientId}/checklists` · `/clients/{clientId}/tags` | List all, archived included |
| `POST` | `/clients/{clientId}/checklists` · `/tags` | Create |
| `PATCH` | `/clients/{clientId}/checklists/{checklistId}` · `/tags/{tagId}` | Change the fields you send |
| `DELETE` | `/clients/{clientId}/checklists/{checklistId}` · `/tags/{tagId}` | Archive. `PATCH` with `"is_active": true` restores it. |

```json
POST /clients/512/checklists
{
  "name": "Drivers",
  "description": "Pre-hire and annual for CDL drivers",
  "organization_id": 1880,
  "items": [
    { "service": "mvr", "renewal_type": "period", "renewal_config": { "months": 12 } },
    { "service": "sanc" },
    { "product_id": 3, "name": "Criminal (national)", "stage": 2 }
  ]
}
```

| Field | Notes |
|---|---|
| `name` | Required on create. A tag's name is unique within the account. |
| `description` | Optional. |
| `organization_id` | Optional. Limits the checklist or tag to one organization. |
| `is_active` | `false` archives it. |
| `items` / `requirements` | Required on create. The lines below, in the order they should appear. |

Each line names its product one of two ways:

| Line field | Notes |
|---|---|
| `product_id` | A product from the [product list](#products). |
| `service` | A service code. A code that covers several products becomes one line per product. |
| `name` | Optional label. Defaults to the product's name. |
| `renewal_type` | `none`, `period` (re-run every `renewal_config.months`), `expiration` (re-run when the underlying document expires, for products that carry one) or `scheduled` (a recurring calendar date). |
| `renewal_config` | For `period`: `{ "months": 12 }`. For `scheduled`: `anchor_month`, `anchor_day`, `interval_months`. |
| `reuse_policy` | `reuse_if_valid` (default), `always_new` or `reuse_same_org_only`: whether a person's still-valid result is reused instead of ordering again. |
| `stage` | `1`, `2`, …: a later stage is ordered only after the earlier stages finish. Leave it out to order immediately. |
| `id` | `PATCH` only: an existing line you are keeping. |

The response returns the full `checklist` (or `tag`), with each line's `id`.

### Updating lines

On `PATCH`, `items` (or `requirements`) is the **whole list**:

- a line with an `id` is kept and updated;
- a line without an `id` is added;
- an existing line you leave out is removed.

A kept line keeps every setting you do not send, so you can rename one line without restating its renewal or stage. Leave `items` out entirely to change only the name, description or organization.

When a change affects people already enrolled, the response includes `enrollment_sync_run_id`. Their progress is recalculated in the background.

### Every line must resolve

If any line names a product the account cannot order, a code that covers nothing, or an `id` that is not on this checklist, **nothing changes**. The call returns `422 UNRESOLVED_LINES` and lists each failing line by its position:

```json
{
  "success": false,
  "error": {
    "code": "UNRESOLVED_LINES",
    "message": "Some lines could not be resolved; nothing was changed",
    "details": { "lines": [ { "index": 1, "service": "zzz", "reason": "not_available" } ] }
  }
}
```

| `reason` | Meaning |
|---|---|
| `not_available` | The product or code is not orderable on this account. Check the [product list](#products). |
| `line_not_found` | The `id` is not a line of this checklist or tag. |
| `id_needs_product_id` | A kept line (`id`) named a code that covers several products. Name it by `product_id`. |

Archiving stops a checklist or tag being offered for new enrollments. People already on it are not affected.

## A typical integration

1. Your customer signs up on your platform. Call `POST /clients` and store `client_id`.
2. If the customer belongs under an account you already created, call `POST /clients/{clientId}/organizations` with their `external_id` instead.
3. Send the user into PSBI with `auto_login_url`. When they come back later, mint a fresh one with `POST /clients/{clientId}/login-link`.
4. Keep their screening in step with your platform's positions through `/checklists` and `/tags`, using `/products` to choose what goes on them.
5. Order and track screening as described in the [Partner API reference](https://psbi.com/developers/partner-api.md).

## Errors

| HTTP | `error.code` | Meaning |
|---|---|---|
| 401 | `MISSING_API_KEY` / `INVALID_API_KEY` | No key, or a wrong or deactivated one. |
| 403 | `CAPABILITY_NOT_ALLOWED` | This part of the API is not turned on for your platform. |
| 403 | `LOGIN_LINK_NOT_ALLOWED` | The user belongs to more than one account and signs in with their password. |
| 404 | `CLIENT_NOT_FOUND` | No account with that id that your platform created. |
| 404 | `ORGANIZATION_NOT_FOUND` / `CHECKLIST_NOT_FOUND` / `TAG_NOT_FOUND` | Not found on this account. |
| 404 | `USER_NOT_FOUND` | No user with that email on the account. |
| 409 | `CLIENT_NOT_OPERABLE` | The account cannot sign in until PSBI activates it. |
| 409 | `EXTERNAL_ID_IN_USE` | Another account or organization already uses that `external_id`. |
| 409 | `LAST_ACTIVE_ORGANIZATION` | An account must keep one active organization. |
| 422 | `VALIDATION_FAILED` | The body failed validation. `details` lists each field. |
| 422 | `USER_NOT_ATTACHABLE` | An email belongs to a PSBI staff account. |
| 422 | `UNRESOLVED_LINES` | A checklist or tag line could not be resolved. Nothing changed. |
| 422 | `ORGANIZATION_CYCLE` | An organization cannot sit under itself or its own child. |
| 500 | `INTERNAL_ERROR` | Something failed on PSBI's side. Retry later, and contact PSBI if it persists. |

## Support

Your PSBI implementation contact issues API keys and turns parts of the API on. For anything else: support@psbi.com, (800) 574-0394.
