# Pathology requests

A **pathology request** orders one or more pathology tests, such as a full blood count, for a patient. You send it with a group API key. An OnEarly doctor reviews it at no charge to you or the patient. The patient then confirms their details, picks a collection centre, pays for any tests Medicare doesn't cover and has their sample collected. The lab reports back to OnEarly. For the tests the patient pays for, you read the results as structured values or download the lab report.

Pathology requests have their own routes under `/api/v1/marketplace/requests`. They carry pathology tests only: imaging is ordered separately.

:::note[Not open everywhere yet]
`POST /api/v1/marketplace/requests` answers `403` in a region where OnEarly hasn't opened pathology requests yet, and for an integration that orders without patient accounts. Your OnEarly contact can tell you when it opens for you.
:::

## Before you start

- **Host.** Call `https://api.onearly.com`. All paths in this section are relative to it. OnEarly sends each request to your group's home region; see [One address in every region](../index.md#one-address-in-every-region).
- **Group API key.** Every endpoint takes a group API key, sent as `Authorization: Bearer oe_sk_…`. See [Group API keys](../authentication.md#group-api-keys). Keep the key on your server.
- **Full-access scope.** The key needs the `*` scope: these routes have no narrower one. Downloading the lab report also works with `content:read`. A key without the scope it needs gets `403` `API_KEY_SCOPE_MISSING`.
- **Your group orders.** A key reads only the requests its own group ordered. Any other request answers `404`, as an unknown id does.
- **Patients act in OnEarly.** Patients confirm details, choose a centre and pay in OnEarly with their own account. This API doesn't do those steps for them.

## The request lifecycle

1. **Order.** You create the request. OnEarly shares it with the patient's account, making one when the patient has none, and starts a Doctor Review. See [Order and cancel](ordering.md).
2. **Doctor Review.** An OnEarly doctor decides which tests to refer under Medicare. The verdict is `eligible` or `not_eligible`. See [Doctor review](tracking.md#doctor-review).
3. **Patient steps.** The patient confirms their details (`details`), picks a collection centre (`centre`), pays for anything not bulk billed (`payment`) and gives their sample (`complete-tests`). See [Progress](tracking.md#progress).
4. **Results.** The lab reports, sometimes in parts. The `results` step is `done` once every test's results are back. See [Results](tracking.md#results).

You can cancel the request until the doctor gives a verdict or the patient starts on it.

## Endpoints

| Method | Path | Summary |
|---|---|---|
| `GET` | `/api/v1/marketplace/services?category=pathology` | The pathology tests you can order. See [Choose tests](#choose-tests). |
| `POST` | `/api/v1/marketplace/requests` | Order a pathology request. Answers `201`. |
| `GET` | `/api/v1/marketplace/requests` | Your group's requests, newest first, with cursor pagination |
| `DELETE` | `/api/v1/marketplace/requests/{nodeLineageUuid}` | Cancel a request. Answers `204`. |
| `GET` | `/api/v1/marketplace/requests/{nodeLineageUuid}/progress` | The patient's steps, payment and whether results are released |
| `GET` | `/api/v1/marketplace/requests/{nodeLineageUuid}/doctor-review` | The doctor's verdict and which tests were referred |
| `GET` | `/api/v1/marketplace/requests/{nodeLineageUuid}/summary` | Who ordered it and whether it can still be cancelled |
| `GET` | `/api/v1/marketplace/requests/{nodeLineageUuid}/results` | The lab's results as structured values |
| `GET` | `/api/download/file/{fileContentUuid}` | Download the lab report PDF |

## Choose tests

Each test on a request names a row of the OnEarly service catalogue by its `slug`. List the pathology rows with `GET /api/v1/marketplace/services?category=pathology`, or read one with `GET /api/v1/marketplace/services/{slug}`.

| Field | Notes |
|---|---|
| `uuid` | The catalogue row's id |
| `slug` | Use it in `services[].slug`, such as `full-blood-count` |
| `title` | The test's name, as the patient and doctor see it |
| `description` | A longer description |
| `category` | `pathology` for the tests you can order here |
| `status` | `ACTIVE` or `INACTIVE`. Only `ACTIVE` rows can be ordered. With no `status` filter, only `ACTIVE` rows are listed. |

A validation failure on these two routes returns the raw validator body `{ "success": false, "error": { … } }`, not the error envelope below.

## Polling

Webhooks don't cover pathology requests yet. Poll `GET /api/v1/marketplace/requests/{nodeLineageUuid}/progress` for each open request, or page through `GET /api/v1/marketplace/requests` to find new results (`resultsStored`). Stop polling a request once its `results` step is `done`, or once you've cancelled it.

## Errors

Errors use the envelope `{ "error": true, "message", "code", "metadata"?, "issues"? }`. The lab report download uses a different shape; see [Download the lab report](tracking.md#download-the-lab-report).

| Status | `code` | When |
|---|---|---|
| `400` | `VALIDATION_ERROR` | The body failed validation, or a service is an `ACTIVE` row from another category, such as imaging. `issues` names the fields when the body failed validation. |
| `400` | `INVALID_CURSOR` | List only: `after` isn't a cursor the list issued. Start again from the first page. |
| `401` | See [Authentication errors](#authentication-errors) | No key, or a key that isn't valid |
| `403` | `INSUFFICIENT_PERMISSIONS` | Create only: `performAs` names another group, the integration orders without patient accounts, or pathology requests aren't open in the region |
| `403` | `API_KEY_SCOPE_MISSING` | The key doesn't have the `*` scope |
| `403` | `INVALID_ACTOR_TYPE` | The `nodeLineageUuid` in the path isn't a UUID |
| `404` | `NOT_FOUND` | No such request, or one your group didn't order. On create: a service slug that is unknown or not `ACTIVE`, or the patient's account has been deleted. |
| `409` | `CONFLICT` | Cancel: the request can no longer be cancelled, or it changed while being cancelled. See [Cancel a request](ordering.md#cancel-a-request). |
| `409` | `EMAIL_ALREADY_IN_USE`, `PHONE_ALREADY_IN_USE`, `IDENTIFIER_CONFLICT` | Create: OnEarly couldn't make the patient's account because the identifier is already taken |
| `421` | `WRONG_REGION` | Retry once at the `base_url` in the body. This body is `application/problem+json`, not the envelope above. See [Wrong region](/errors/wrong-region). |
| `500` | `INVITE_NOT_SENT` | Create: the patient's account is in another region. See [Who the patient is](ordering.md#who-the-patient-is). |

### Authentication errors

A missing or rejected key answers `401` with one of these codes.

| Code | Meaning |
|---|---|
| `MISSING_AUTHORIZATION_HEADER` | No `Authorization` header was sent |
| `API_KEY_INVALID` | The key isn't recognised |
| `API_KEY_REVOKED` | The key has been revoked |
| `API_KEY_EXPIRED` | The key's expiry date has passed |
| `USER_API_KEY_MCP_ONLY` | A personal API key was used. Personal keys don't work on pathology requests, though they can download files. |

If the key couldn't be checked at all, the request is treated as having no key and answers `MISSING_AUTHORIZATION_HEADER`. A bearer token that doesn't start with `oe_sk_` is checked as a sign-in token instead, and can answer a token code such as `INVALID_JWT` or `EXPIRED_JWT`.

Source: https://docs.onearly.com/api/pathology/
