> ## Documentation Index
> Fetch the complete documentation index at: https://developers.vibrant-wellness.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sandbox order simulator

> Move your own sandbox orders forward to test status, reports, and webhooks end to end.

> [!NOTE]
>
> **WIP — coming soon.** This page describes the planned simulator; the endpoint, fields, and
> values may change. It is not available yet.

Orders you place in sandbox create no real samples, so their kits, lab receipt, and reports do not
progress the way they do in production. The order simulator moves an order you placed with
[`POST /orders`](https://developers.vibrant-wellness.com/api-reference/orders/place) to the state you choose.
[Get orders](https://developers.vibrant-wellness.com/api-reference/orders/status.md), the [Report endpoint](https://developers.vibrant-wellness.com/api-reference/reports/get.md), and
[webhooks](https://developers.vibrant-wellness.com/concepts/webhooks.md) then all show that state, so you can test your whole integration:
place an order, react to its events, query it, and fetch its report.

## Simulator or webhook `simulate`

The webhooks API already has [`simulate`](https://developers.vibrant-wellness.com/concepts/webhooks#simulate-an-order-in-sandbox), and it
stays available. The two test different things:

| | Webhook `simulate` | Order simulator |
| :- | :- | :- |
| Order | A new `SIM…` accession for each run | An order you placed with `POST /orders` |
| Get orders and the Report endpoint | Do not return the `SIM…` accession | Return the order in its simulated state |
| Webhook events | Sent only to the endpoint you call `simulate` on | Sent to your clinic's endpoints, as for any order change |
| Webhook endpoint required | Yes | No |
| Use it to test | Your webhook receiver: verification, retries, ordering, duplicates | Your integration end to end |

## Move an order

```bash theme={null}
curl -X POST "https://api-sandbox.vibrant-america.com/v1/sandbox/orders/simulate" \
  -H "Authorization: Bearer $ACCESS_TOKEN" -H "Content-Type: application/json" \
  -d '{ "accessionId": "2607216002", "targetState": "kit_delivered" }'
```

The simulator accepts the request and moves the order asynchronously. Read the result from Get
orders, the Report endpoint, or the webhook events; there is no separate progress endpoint.

| Field | Required | Description |
| :- | :- | :- |
| `accessionId` | One of `accessionId` or `placerId` | The `accessionId` that `POST /orders` returned. |
| `placerId` | One of `accessionId` or `placerId` | The `placerId` you placed the order with. |
| `targetState` | One of `targetState` or `scenario` | The state to move the order to. See [States](#states). |
| `scenario` | One of `targetState` or `scenario` | Steps to play one after another. See [Scenarios](#scenarios). |
| `stepIntervalSeconds` | No | With `scenario`: seconds between steps. |
| `issues` | No | The complete list of issue codes the order should have. Omit it to keep the current issues; send `[]` to clear them. See [Issues](#issues). |
| `generatedReportCount` | No | How many of the order's reports are generated, from `0` to its `totalReportCount`. See [Report counts](#report-counts). |

Authenticate with an access token from your sandbox client credentials, requested with
`algorithm=RS256` as for the
[webhook management API](https://developers.vibrant-wellness.com/concepts/webhooks.md#authentication-for-the-management-api).

## States

Set any state later than the order's current one. Each state includes the ones before it: moving a
new order straight to `report_final` also fills in kit shipping and lab receipt. Get orders and
webhooks use different status values; see [Status values](https://developers.vibrant-wellness.com/concepts/webhooks.md#status-values).

| `targetState` | Get orders `status` | Webhook `unifiedStatus` | Details |
| :- | :- | :- | :- |
| `placed` | `placed` | `awaiting_sample` | Every order starts here. |
| `kit_shipped` | `kit_shipped` | `kit_in_transit` | `kit.status: "shipped"`, with carrier, tracking number, and `shippedAt`. |
| `kit_in_transit` | `kit_shipped` | `kit_in_transit` | `kit.status: "in_transit"`. |
| `kit_delivered` | `kit_delivered` | `kit_with_patient` | `kit.status: "delivered"`, with `deliveredAt`. |
| `sample_in_transit` | `sample_in_transit` | `sample_in_transit` | The sample is on its way to the lab. |
| `sample_received` | `sample_received` | `sample_received` | The lab has the sample; the order can no longer be canceled. |
| `analyzing` | `analyzing` | `analyzing` | `report.status: "registered"`; no results yet. |
| `report_preliminary` | To be confirmed | To be confirmed | `report.status: "preliminary"`; the Report endpoint returns preliminary [demo results](#reports). |
| `report_final` | `report_available` | `results_ready` | `report.status: "final"`; the Report endpoint returns final demo results and PDFs. |

* **Forward only.** An earlier state is rejected. To run a flow again, place a new order. The
  [report count](#report-counts) can go up or down.
* **The current state changes nothing** and sends no event. To change only the issues or the report
  count, send the current state with `issues` or `generatedReportCount`.
* **A jump over several states** produces one webhook event; its `changes` lists every field that
  changed.

## Scenarios

A scenario plays several steps on the order, `stepIntervalSeconds` apart, and each step is
delivered as its own webhook event. Run a scenario on a newly placed order. Scenarios use the names
of webhook `simulate`:

| `scenario` | Steps |
| :- | :- |
| `kit_to_results` | Kit shipped → kit delivered → sample shipped → lab receipt → analyzing → results ready. |
| `redraw` | Kit shipped → lab receipt → redraw requested → new kit shipped → sample shipped → analyzing → results ready. |
| `issues` | `billing` raised → `missing_tubes` raised → both resolved. |

The steps follow webhook `simulate` without its partial-results steps, because how many reports an
order produces depends on its panels. To test partial results, set the
[report count](#report-counts).

## Issues

`issues` sets the order's open issues with the [webhook issue codes](https://developers.vibrant-wellness.com/concepts/webhooks.md#issues), for
example `["billing"]`. List every issue the order should have: omit `issues` to keep the current
ones, and send `[]` to clear them all.

Issues behave as in production. Get orders and the Report endpoint show them with their
report-blocking flags, a blocking issue withholds result content until you clear it, and each change
sends an `order.status_changed` with `issues` in `changes`. See [Exceptions](https://developers.vibrant-wellness.com/concepts/exceptions.md).

## Report counts

Get orders returns how many reports the order has in `report.totalReportCount` (the Report
endpoint's `total_report_count`, webhook `reports.total`). The simulator does not change it.

`generatedReportCount` sets how many of them are generated: any number from `0` to
`totalReportCount`. Unlike the state, it can go up or down, so you can test 1 of 3, then 3 of 3,
then 2 of 3. A number below `0` or above `totalReportCount` is rejected. Set it on an order at
`analyzing` or later, or in the request that moves the order there.

```bash theme={null}
curl -X POST "https://api-sandbox.vibrant-america.com/v1/sandbox/orders/simulate" \
  -H "Authorization: Bearer $ACCESS_TOKEN" -H "Content-Type: application/json" \
  -d '{ "accessionId": "2607216002", "targetState": "analyzing", "generatedReportCount": 1 }'
```

* **Default.** Moving to `report_final` generates every report, unless you send
  `generatedReportCount` with it.
* **Where it shows.** Get orders `report.generatedReportCount`, the Report endpoint's
  `total_generated_report_count`, and webhook `reports.generated`.
* **Events.** Each change sends an `order.status_changed` with `reports` in `changes`. Webhook
  `unifiedStatus` follows the count as in production: for example, `results_partial` at 1 of 3
  and `results_ready` at 3 of 3.
* **To be confirmed:** which reports are generated first, and Get orders `status` and
  `report.status` while only some reports are generated.

## Reports

Reports with results come back from the Report endpoint as demo data: a FHIR `DiagnosticReport`
with made-up values, and a PDF watermarked **SANDBOX**. [Generated reports](#report-counts) have
final results. The others have preliminary results at `report_preliminary`, and none otherwise. The
structure is the same as in production, so you can test how you parse and store results; the values
have no clinical meaning.

## Webhooks

Simulated changes are delivered like real ones: to every endpoint of your clinic that subscribes to
the event type, by the normal [trigger rules](https://developers.vibrant-wellness.com/concepts/webhooks.md#what-triggers-an-event). You do not
need a webhook endpoint to use the simulator; an integration that only polls reads the same states
from Get orders and the Report endpoint.

## Cancellation

Cancel a simulated order with [`POST /orders/cancel`](https://developers.vibrant-wellness.com/api-reference/orders/cancel), as in
production. The [cancellation policy](https://developers.vibrant-wellness.com/api-reference/orders/cancel.md#the-policy) applies to the
simulated state, so you can test each case: before the kit ships, after it ships, and after lab
receipt (`not_cancellable`). After cancellation, you can still move the kit (`kit_shipped`,
`kit_in_transit`, `kit_delivered`); other states are rejected.

## Access and limits

* Sandbox only: in production, the endpoint returns `404`.
* Only orders your clinic placed through this API. An order of another clinic, or an unknown order,
  returns `404`. An order placed in the Vibrant Portal returns `not_placed_via_api`, as for
  [looking up an order by `accessionId`](https://developers.vibrant-wellness.com/api-reference/orders/status#look-up-by-accessionid).
* Rate limits will be listed here.

## Example: a report held up by an issue

**1. Place an order**

Place an order in sandbox with [`POST /orders`](https://developers.vibrant-wellness.com/api-reference/orders/place) and save its
`accessionId`, for example `2607216002`.

**2. Move it to final with a billing issue**

```bash theme={null}
curl -X POST "https://api-sandbox.vibrant-america.com/v1/sandbox/orders/simulate" \
  -H "Authorization: Bearer $ACCESS_TOKEN" -H "Content-Type: application/json" \
  -d '{ "accessionId": "2607216002", "targetState": "report_final", "issues": ["billing"] }'
```

You receive one `order.status_changed`. The Report endpoint returns `status: "final"` and lists
the `billing` issue; while it blocks the report, the results are withheld.

**3. Clear the issue**

```bash theme={null}
curl -X POST "https://api-sandbox.vibrant-america.com/v1/sandbox/orders/simulate" \
  -H "Authorization: Bearer $ACCESS_TOKEN" -H "Content-Type: application/json" \
  -d '{ "accessionId": "2607216002", "targetState": "report_final", "issues": [] }'
```

You receive an `order.status_changed` with `issues` in `changes`. Once the
[`reportReady`](https://developers.vibrant-wellness.com/concepts/webhooks#report-workflow) reason is available (coming soon), the same
event can also carry it. Fetch the report again: with no blocking issue left, the demo results
and PDF are included.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.