API reference
Affinity API for platforms and practices that order from the pharmacy network. If a response or a page is wrong or unclear, send POST /v1/feedback with an Idempotency-Key, a short message and the requestId from the response. Do not include patient information.
https://api.affinityrx.com
2026-11-01
Endpoints
Account
Read the organization and mode you act as
Feedback
Send feedback
Medications
List medications · Read a medication
Orders
Create, sign and submit an order · List orders · Search orders · Read an order · Cancel an order
Practices
Create a practice · List practices · Read a practice · Update a practice
Webhooks
List webhook endpoints of the current mode · Add a webhook endpoint · Change a webhook endpoint's URL · Delete a webhook endpoint · Resend failed webhook deliveries
Webhook events
Affinity sends these JSON payloads to your registered endpoint. Read Receive order updates for signature verification and retries.
WebhookEvent
When type is
order.cancelled or order.delivered or order.failed or order.processing or order.shipped or order.submitted or order.updated:
id
string
required
The event identifier; retries and resends keep the same identifier.
Pattern: ^evt_[0-7][0-9a-hjkmnp-tv-z]{25}$
type
OrderEventType
required
The event type; ignore event types that you do not recognize.
Allowed: "order.cancelled", "order.delivered", "order.failed", "order.processing", "order.shipped", "order.submitted", "order.updated"
createdAt
string
required
When the event was created.
Format: date-time
data
object
required
The event payload.
Show data fields
order
WebhookOrder
required
The order's operational details without patient data or prescription clinical details. failureReason is always Affinity's own summary; a reason written by Affinity staff is in the order that GET /v1/orders/{orderId} returns.
Show order fields
cancelRequestedAt
string | null
required
When cancellation was requested, or null when no cancellation is waiting.
Format: date-time
externalOrderId
string | null
required
Your order identifier, unique within the practice and mode. A failed or cancelled order keeps it.
failureReason
string | null
required
Why the order failed, for a person to read. Null unless the order failed; a refused cancel leaves it null.
id
string
required
The public record identifier.
Pattern: ^ord_[0-7][0-9a-hjkmnp-tv-z]{25}$
shipments
Shipment[]
required
The shipped packages, oldest first; a split shipment or reshipment adds a package.
Show shipments fields
Array items · Shipment
carrier
string | null
required
The carrier name, or null when it is unknown.
trackingNumber
string
required
The package tracking number.
trackingUrl
string | null
required
The carrier's tracking page for this package, or null when the carrier has none.
Format: uri
prescriptions
object[]
required
The prescriptions for this order's patient.
Show prescriptions fields
Array items · object
id
string
required
The prescription's public identifier.
Pattern: ^rx_[0-7][0-9a-hjkmnp-tv-z]{25}$
status
string
required
The current fulfillment status.
Known values: "awaiting_approval", "submitted", "processing", "shipped", "delivered", "cancelled", "failed"
failureReason
string | null
required
Why the order failed, for a person to read. Null unless the order failed; a refused cancel leaves it null.
status
string
required
The current fulfillment status.
Known values: "awaiting_approval", "submitted", "processing", "shipped", "delivered", "cancelled", "failed"
trackingUrl
string | null
required
The carrier's tracking page for the newest package. Null when there is no package yet or the carrier has no tracking page.
Format: uri
updatedAt
string
required
When the record was last updated.
Format: date-time
When type is
prescription.failed or prescription.cancelled:
id
string
required
The event identifier; retries and resends keep the same identifier.
Pattern: ^evt_[0-7][0-9a-hjkmnp-tv-z]{25}$
type
PrescriptionEventType
required
The event type; ignore event types that you do not recognize.
Allowed: "prescription.failed", "prescription.cancelled"
createdAt
string
required
When the event was created.
Format: date-time
data
object
required
The event payload.
Show data fields
order
WebhookOrder
required
The order's operational details without patient data or prescription clinical details. failureReason is always Affinity's own summary; a reason written by Affinity staff is in the order that GET /v1/orders/{orderId} returns.
Show order fields
cancelRequestedAt
string | null
required
When cancellation was requested, or null when no cancellation is waiting.
Format: date-time
externalOrderId
string | null
required
Your order identifier, unique within the practice and mode. A failed or cancelled order keeps it.
failureReason
string | null
required
Why the order failed, for a person to read. Null unless the order failed; a refused cancel leaves it null.
id
string
required
The public record identifier.
Pattern: ^ord_[0-7][0-9a-hjkmnp-tv-z]{25}$
shipments
Shipment[]
required
The shipped packages, oldest first; a split shipment or reshipment adds a package.
Show shipments fields
Array items · Shipment
carrier
string | null
required
The carrier name, or null when it is unknown.
trackingNumber
string
required
The package tracking number.
trackingUrl
string | null
required
The carrier's tracking page for this package, or null when the carrier has none.
Format: uri
prescriptions
object[]
required
The prescriptions for this order's patient.
Show prescriptions fields
Array items · object
id
string
required
The prescription's public identifier.
Pattern: ^rx_[0-7][0-9a-hjkmnp-tv-z]{25}$
status
string
required
The current fulfillment status.
Known values: "awaiting_approval", "submitted", "processing", "shipped", "delivered", "cancelled", "failed"
failureReason
string | null
required
Why the order failed, for a person to read. Null unless the order failed; a refused cancel leaves it null.
status
string
required
The current fulfillment status.
Known values: "awaiting_approval", "submitted", "processing", "shipped", "delivered", "cancelled", "failed"
trackingUrl
string | null
required
The carrier's tracking page for the newest package. Null when there is no package yet or the carrier has no tracking page.
Format: uri
updatedAt
string
required
When the record was last updated.
Format: date-time
prescriptionId
string
required
The public identifier of the prescription that changed.
Pattern: ^rx_[0-7][0-9a-hjkmnp-tv-z]{25}$
When type is
webhook_endpoint.test:
id
string
required
The event identifier; retries and resends keep the same identifier.
Pattern: ^evt_[0-7][0-9a-hjkmnp-tv-z]{25}$
type
WebhookEndpointTestEventType
required
The event type; ignore event types that you do not recognize.
Allowed: "webhook_endpoint.test"
createdAt
string
required
When the event was created.
Format: date-time
data
object
required
The event payload.
Request conventions
Authentication
Send your API key as Authorization: Bearer sk_test_…. The key sets the organization and the mode (Test or Live). Keep the key on your server.
The x-affinity-api-key header is still accepted but deprecated. Use Authorization: Bearer <key> instead. Bearer takes precedence if both headers are sent, even when the Bearer credential is invalid.
Versioning
Send Affinity-Version: 2026-11-01 with each request. A missing or unknown value returns 400 unsupported_api_version. Paths stay under /v1.
Idempotency
The Idempotency-Key header is required on POST /v1/orders. A replay returns 200 with the order as it is now. A missing key returns 400 invalid_request.
| Request | Idempotency-Key |
|---|---|
POST /v1/feedback
| Required |
POST /v1/orders
| Required |
POST /v1/orders/{orderId}/cancel
| Required |
POST /v1/practices
| Required |
PATCH /v1/practices/{practiceId}
| Required |
POST /v1/webhook-endpoints
| Required |
PATCH /v1/webhook-endpoints/{webhookEndpointId}
| Required |
POST /v1/webhook-endpoints/{webhookEndpointId}/resend-failed
| Required |
The table shows each public operation that accepts Idempotency-Key and whether the key is required. Dashboard webhook test sends also require it. A missing or invalid required key returns 400. DELETE routes do not require the header.
Use 1 to 255 printable ASCII characters without spaces. Use a fresh key for each new action. Retry an uncertain request with the same key and body. A changed body returns 409 idempotency_key_reused. Order creation and cancellation replays return the first response's status with the order as it is now. A webhook endpoint creation replay rebuilds its response from the endpoint, and returns 404 after the endpoint is deleted. Other keyed operations return their stored first response. Read Retry safely for retention and webhook creation replay rules.
Lists
A list returns { object: "list", url, data, hasMore, nextCursor }. Each endpoint sets its order: orders, practices and webhook endpoints are newest first, and medications are A to Z by name. Orders and practices also accept sort. Send limit (default 25, maximum 100). To get the next page, send nextCursor as startingAfter, and keep filters and sort unchanged. Lists page forward only. There are no total counts.
Clients
Call the API over HTTP. The guides show each request as a curl command and as TypeScript with the built-in fetch. For TypeScript types, use openapi-typescript: it generates them from the OpenAPI document.
Other generators are tested. With each change to the document, these generators build a client that creates, lists and reads a Test order: openapi-generator 7.27 (TypeScript Fetch and Axios, Go, Python and Java), openapi-generator 7.10 (TypeScript Axios, Go and C#), oapi-codegen and Fern.
Some generators are not supported. openapi-generator 7.10 for TypeScript Fetch, Python and Java cannot read the document's OpenAPI 3.1 nullable fields and enum names; use 7.17 or later. openapi-generator 7.27 for C# and NSwag are not supported yet; call the API over HTTP instead.
In a Java client that uses Jackson, set JsonInclude.Include.NON_NULL on its ObjectMapper. Otherwise the client sends each unset optional field as null, and the API refuses the request with 400.
Errors
Errors are flat problem documents with a lowercase code, status, detail and requestId. Read Errors.