> This page is for version v2.
> For other versions, use one of these documentation indexes:
> - v1 (default): https://developers.outpave.com/v1/llms.txt
> - v2: https://developers.outpave.com/v2/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.outpave.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.outpave.com/_mcp/server.

# Customer Portal ingestion

The Customer Portal API is the same in v1 and v2. Set `PORTAL_HOST` to the Customer Portal API domain assigned to your integration.

## Authenticate

Your platform receives a Customer Portal API key. Keep it on a trusted server and never ship it in a browser or mobile app.

#### Exchange the key for an access token

The API key is accepted only by this endpoint.

```bash
curl -X POST "https://$PORTAL_HOST/api/v1/access-token" \
  -H "Authorization: Bearer $PORTAL_API_KEY"
```

```json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "tokenType": "Bearer",
  "expiresIn": 1800,
  "expiresAt": 1717852800000
}
```

#### Send the token on every other call

```bash
curl "https://$PORTAL_HOST/api/v1/ping" \
  -H "Authorization: Bearer $TOKEN"
```

```json
{ "message": "pong" }
```

When the token expires, exchange the API key again. If your platform has an IP allowlist, an exchange from any other address returns `401`.

## Send records

Each record type has one create-or-update endpoint.

| Record   | Create or update                | Read                                |
| -------- | ------------------------------- | ----------------------------------- |
| Merchant | `POST /api/v1/onboard/merchant` | `GET /api/v1/onboard/merchant/{id}` |
| Business | `POST /api/v1/business`         | `GET /api/v1/business/{id}`         |
| Contact  | `POST /api/v1/contact`          | `GET /api/v1/contact/{id}`          |
| Invoice  | `POST /api/v1/invoice`          | `GET /api/v1/invoice/{id}`          |

`{id}` is the record's `id`, a UUID, or your own `externalId`.

Create the merchant first. An invoice names its `merchant` by `id` or `externalId` and is addressed to exactly one of `recipientContact` or `recipientBusiness`. To attach documents to an invoice, send `multipart/form-data` with the invoice JSON in a `data` field and the files in `files`.

```bash
curl -X POST "https://$PORTAL_HOST/api/v1/onboard/merchant" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "externalId": "merchant_123", "name": "Acme Supply" }'
```

The record comes back under `data`.

## Retry safely

Send your own `externalId` on every record. Sending the same `externalId` again updates that record instead of creating another, so you can retry a JSON request. Without an `externalId`, a retry can create a duplicate.

`externalId` deduplicates the invoice, not its files. Every multipart request stores its `files` as new attachments, so resending the same files adds them again. Invoice reads do not list attachments, so you cannot check for them through this API. Send field updates as JSON, and resend files only when you know the earlier upload did not succeed.

## Errors

Errors carry a JSON body with an `error` message. Validation failures add a `details` array. Branch on the HTTP status, not on the message.

| Status | Meaning                                                    | What to do                                         |
| ------ | ---------------------------------------------------------- | -------------------------------------------------- |
| `400`  | The body failed validation.                                | Fix the fields named in `details`.                 |
| `401`  | The key or token is missing, invalid or expired.           | Exchange the API key again.                        |
| `404`  | No record with that `id` or `externalId` on your platform. | Check the identifier.                              |
| `409`  | Another record already holds a unique value.               | Read the existing record.                          |
| `429`  | Too many requests.                                         | Wait the seconds in `RateLimit-Reset`, then retry. |
| `500`  | Unexpected error.                                          | Retry with backoff.                                |