An error response is a flat problem document (RFC 9457) with the content type application/problem+json. All members are at the top level.
| Field | Meaning |
|---|---|
code | The error code, in lowercase snake_case. Branch on this value. |
status | The HTTP status. It is the same as the response status. |
title | A short name of the error. |
detail | A sentence for a person about this failure. The text can change. Do not branch on it. |
type | The URL of the page for the code on this site. |
instance | The request path, without the query string. |
requestId | The ID of the request. Give it to Affinity when you report a problem. |
issues | Field details for 400 invalid_request, path IDs of another resource type with 404 not_found, and some 422 responses. |
data | Optional recovery fields, such as practiceId or orderId on duplicate conflicts. |
traceId | Optional. The trace of the request. |
The X-Request-Id response header matches requestId. Keep it for support. Error messages never contain patient data.
Affinity generates the request ID. A caller-supplied X-Request-Id is ignored. A valid W3C traceparent can supply the trace ID for distributed tracing.
Field issues
A request that does not match the endpoint gets 400 invalid_request. Examples include a missing field, a malformed phone number, or a wrong resource type in a body or query field.
{
"type": "https://docs.affinityrx.com/errors/invalid-request",
"title": "Invalid Request",
"status": 400,
"detail": "patient.phone: A required value is missing. Expected string",
"instance": "/v1/orders",
"code": "invalid_request",
"requestId": "de8212fb-9a33-4f72-bac6-618995c4f7c2",
"issues": [
{
"code": "invalid_value",
"field": "patient.phone",
"message": "A required value is missing. Expected string",
"path": ["patient", "phone"]
}
]
}
A valid ID for another resource type in the endpoint path gets 404 not_found. The route ID validator includes issues with the path field. For example, a patient ID in GET /v1/orders/{orderId} returns this error. A malformed path ID gets 400 invalid_request.
A request that is well formed but breaks a rule gets 422. Examples: a quantity that the pharmacy does not dispense, a required compounding reason, a restricted state.
{
"type": "https://docs.affinityrx.com/errors/invalid-order",
"title": "Invalid Order",
"status": 422,
"detail": "prescriptions[0].quantity: Send one of these quantities: 20 g. See quantities in GET /v1/medications/{medicationId}.",
"instance": "/v1/orders",
"code": "invalid_order",
"requestId": "e3bb20b9-e362-4da8-9764-5beffde04029",
"issues": [
{
"code": "invalid",
"field": "prescriptions[0].quantity",
"message": "Send one of these quantities: 20 g. See quantities in GET /v1/medications/{medicationId}.",
"path": ["prescriptions", 0, "quantity"]
}
]
}
These field issues have the same shape:
| Field | Meaning |
|---|---|
code | What is wrong with the field, for example invalid_value, required or restricted_state. |
field | The place of the value as a string, for example prescriptions[0].compoundingReason. |
path | The same place as an array, for example ["prescriptions", 0, "compoundingReason"]. |
message | A sentence for a person. Show it next to the field. |
Report a problem
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.
Set message to a description of the problem. Include pageUrl for a documentation problem. Omit requestId when no response exists.
The endpoint accepts requests without credentials. Agents can use an API key. A 202 response confirms receipt.
Retries
- For
409 request_in_progressor429, wait before you retry. Repeat the unchanged request with the sameIdempotency-Key, when present. - For other
4xxerrors, follow the code's recovery instructions. Change the request or resolve the reported problem before you retry. - Retry
500and503with backoff. - For practice creation or updates, order creation or cancellation, webhook mutations and feedback, retry with the same
Idempotency-Keyand the same body. Affinity does not repeat the action. Order creation returns200with the order as it is now. Cancellation returns the first response's status code with the order as it is now. Webhook endpoint creation rebuilds its response, including the signing secret within the key's lifetime. It returns404after the endpoint is deleted. Other keyed requests return the first response.
Codes for API key requests
| Code | Status | Meaning |
|---|---|---|
invalid_cursor | 400 | The list cursor belongs to another list or to other filters. |
invalid_path | 400 | The path has a trailing /, a . or .. segment, an encoded /, a backslash, or an empty segment that reached the API. Repeated slashes may be normalized before reaching the API. |
invalid_request | 400 | A field or header is missing or malformed, a body or query ID has the wrong type, or the JSON body contains invalid UTF-8. |
unsupported_api_version | 400 | The Affinity-Version header is missing or names an unknown version. |
unauthorized | 401 | The API key or the session is missing, wrong, revoked or expired. |
dashboard_only | 403 | API keys cannot call this route. You manage it in the Affinity app. |
forbidden | 403 | Your role or organization type cannot do this. Only admins manage API keys. Pharmacies do not receive order webhooks, and managed practices use their platform's webhooks. |
live_key_required | 403 | Only a Live API key can turn a practice's Live access on or off. |
live_mode_required | 403 | The change affects Live, so only a Live caller can make it: turning a practice's Live access on or off, changing a Live practice's name, phone and address, which Live orders send to the pharmacy, or deleting an organization with Live access. |
mode_not_enabled | 403 | Live is turned off, so new Live orders and new Live API keys are refused. Live orders need Live access on the practice and its platform. Existing keys still read records, cancel orders and manage webhooks with their existing permissions. |
platform_live_disabled | 403 | Your platform does not have Live access, so it cannot give Live access to a practice. |
platform_only | 403 | Only a platform manages practices. |
staff_only | 403 | The request requires Affinity staff access, including orders with the reserved pharmacy verification note. |
not_found | 404 | The record or route does not exist, belongs to another organization or mode, or the path ID names another resource type. |
method_not_allowed | 405 | The path exists, but not with this HTTP method. |
cancel_refused | 409 | The cancel request failed or the pharmacy refused it. The order keeps its status. |
cannot_cancel | 409 | The order is shipped, delivered or failed, so it cannot be cancelled. |
idempotency_key_reused | 409 | The Idempotency-Key was used before with a different request body, or its first result is not available. |
invalid_transition | 409 | The order cannot change that way from its current status. |
order_already_exists | 409 | This practice already has an order with the same externalOrderId in this mode. |
order_changed | 409 | The order changed while the request ran. |
payment_method_required | 409 | A Live order needs a payment method on file. The payer of the order (the platform, or the independent practice) pays each Live order with its account credit, then its default payment method. It has no default payment method, and its credit does not cover the order, so no order was created or Live was not turned on. |
practice_already_exists | 409 | Another active practice of this platform already uses this externalId. |
request_in_progress | 409 | The first request with this Idempotency-Key has not finished. |
payload_too_large | 413 | The request body is larger than the route's limit: 512 KiB (524,288 bytes) for order writes, 1 MiB (1,048,576 bytes) for other routes. Requests above the gateway limit of 10 MiB may be rejected before the API can return a problem document. |
unsupported_media_type | 415 | The request body is not JSON. |
invalid_address | 422 | The practice has no address, and the address update omits required fields. |
invalid_order | 422 | The order is well formed but breaks an ordering rule. This includes compounding reasons, state restrictions, quantities, shipping options, practice contact details and placeholder values. Platform keys must send practiceId. All API keys must send prescriber. |
invalid_practice_text | 422 | PerfectRx cannot print a character in the practice name or address, the practice name exceeds 100 characters, the combined address lines exceed 70 characters, or address.line2 is see notes, TBD or unknown. |
invalid_webhook_url | 422 | The URL supplied to create or update a webhook endpoint fails public HTTPS validation or host resolution. |
medication_not_visible | 422 | A selected medication does not exist, is disabled, is hidden for the practice or its platform, is research use only (RUO) and the practice has no RUO access, or is a controlled substance, which cannot be ordered yet. |
practice_contact_required | 422 | The practice update sends null for address or phone. Pharmacies need both on every order, so a practice keeps them. |
too_many_webhook_endpoints | 422 | The organization has 16 webhook endpoints in this mode. |
rate_limit_exceeded | 429 | Too many requests with one API key on one API server, too many requests of one customer (a platform and its practices, or an independent organization) in progress at the same time on one API server (Test and Live together), or too many invitation emails, feedback submissions, sign-in requests or code requests in a short time. One API key averages 25 requests each second on each API server, with bursts of up to 50. The count is separate on each server. Invitation emails are limited to three per hour per target email per organization and fifty per day per organization. |
internal_error | 500 | The API could not complete the request because of an unexpected error. |
billing_unavailable | 503 | Billing is not available now. |
service_unavailable | 503 | The API or a service that it needs is not available now. |
Codes in the Affinity app only
| Code | Status | Meaning |
|---|---|---|
invalid_mode | 400 | A dashboard request sent no Affinity-Mode, or a value other than test or live. |
cross_site_request | 403 | A write with a session cookie did not come from an Affinity app. |
named_staff_only | 403 | Only Dawson or Tim can apply or reject a price change. |
npi_required | 403 | The signed-in person has no NPI on their profile, so they cannot sign as themselves. |
platform_managed | 403 | Only the practice's platform can delete this practice. |
prescriber_name_required | 403 | The signed-in member has no valid first and last name, so they cannot sign an order. |
signed_in_user_changed | 403 | A dashboard page wrote for a person who is no longer signed in: someone else signed in from another tab of the same browser. |
account_deactivated | 409 | Staff tried to add a person whose account is deactivated. They cannot sign in. |
billing_managed_by_platform | 409 | The practice's platform pays for it, so the practice has no billing portal. |
billing_payer_busy | 409 | Another billing action is running for this organization. |
billing_payer_lease_lost | 409 | A billing action stopped before it finished because it lost its lock. |
cannot_dismiss | 409 | The order is not failed, so it cannot be dismissed from Needs attention. |
conflict | 409 | The account change conflicts with the current state, for example an email that another account uses. |
controlled_not_sendable | 409 | The order names a controlled medication, which cannot be ordered yet. Nothing was charged or sent. |
invoice_incomplete | 409 | Orders are still being added to this draft, so it can't be approved yet. |
invoice_not_finalized | 409 | Only an invoice approved without email, and not yet paid, void or emailed, can be emailed. |
invoice_total_mismatch | 409 | The draft's total in Stripe is not what its orders are billed, so it is not finalized. |
last_admin | 409 | An organization needs at least one admin. |
member_changed | 409 | The person changed after the screen loaded: an invited person joined, or a removed member got a new invitation. Nothing was removed. |
not_a_draft | 409 | The invoice status does not permit the requested action. |
npi_in_use | 409 | Another account has this NPI. One NPI belongs to one person. |
order_already_billable | 409 | The full order is already marked billable or linked to an invoice. |
order_at_pharmacy | 409 | The pharmacy confirmed the held order, so Resend cannot send it again. This includes an order open for over three business days and a confirmed order the status check no longer finds. |
order_held | 409 | A held order ends failed or cancelled only from its held panel. |
order_may_be_at_pharmacy | 409 | A held order may be at the pharmacy, or the pharmacy may still fill it, so it cannot be failed without the pharmacy's confirmation. |
order_not_held | 409 | The order is not a held Live submission. |
order_not_sent | 409 | Affinity has not sent the order to the pharmacy, so staff cannot set it processing, shipped or delivered. |
order_not_shipped | 409 | The pharmacy has not shipped the order, so its shipping option is still the one Affinity sends. |
order_rejected_by_pharmacy | 409 | The pharmacy rejected the held order after it received it, so Resend cannot send it. |
orders_in_progress | 409 | The organization has Live orders that a pharmacy is still filling. Test orders do not block deletion. |
organization_archived | 409 | The organization is deleted, so its prices do not change. |
patient_changed | 409 | The patient changed after the dashboard read it, so the dashboard order was not signed. Nothing was saved or sent. |
payment_declined | 409 | The payment for this order failed, so the order was not sent to the pharmacy. It waits for Affinity staff. |
payment_method_pending | 409 | Stripe did not finish saving the payment method, so it is not the default payment method yet. |
pharmacy_cancels_by_phone | 409 | The pharmacy has no cancel call, so Resend cannot send the held cancel. It cancels by phone only. |
price_change_decided | 409 | The price change was applied, rejected or replaced before. |
price_change_preview_changed | 409 | The prices that the change moves changed after the page loaded. |
price_change_stale | 409 | The organization got new pricing terms after this change was proposed. |
price_changed | 409 | A reviewed prescription or shipping charge changed before the app signed the order. |
price_review_required | 409 | The app's new order request did not include the reviewed prices. |
pricing_busy | 409 | Another price change or a catalog update is in progress. |
review_not_available | 409 | Only a platform's or an independent practice's Live orders are reviewed by Affinity staff. |
reward_points_insufficient | 409 | The practice does not have the Affinity Rewards points that this order uses. Points are for Live orders only. No order was created. |
shipment_not_billable | 409 | The order is not a failed Live order eligible for Affinity billing. |
billing_email_required | 422 | The invoice would be emailed, but the payer has no Stripe billing email. |
confirmation_required | 422 | A price change sets a price above the customer's tier price, and the staff member did not confirm it. |
credit_refused | 422 | Stripe refused the account credit, so no credit was added. |
invalid_failure_reason | 422 | A staff failure reason must contain 1 to 500 characters. |
invalid_note | 422 | A staff note must contain 1 to 500 characters. |
invalid_npi | 422 | The NPI is not a valid 10-digit NPI. |
invalid_patient | 422 | The dashboard tried to change the first or last name of a patient whose name the pharmacy keeps. Nothing was saved. |
invalid_price | 422 | A price is not dollars with at most two decimals. |
invalid_profile_text | 422 | address.line2 on PATCH /v1/me is see notes, TBD or unknown. Those values are not a suite. |
invalid_shipping_option | 422 | The shipping option does not belong to the order's pharmacy. |
invalid_terms | 422 | The catalog refuses the pricing terms: a price below the pharmacy's cost, an item that is switched off, a deal on an item only some customers can order, or a second deal for one drug. |
invoice_credit_exceeds_total | 422 | The invoice credit makes the draft total negative. |
invoice_too_many_items | 422 | The draft would list more items than Stripe allows on one invoice (250). |
no_change | 422 | The proposed pricing terms are the terms that the organization pays now. |
tier_inherited | 422 | A practice under a platform pays its platform's prices, so it has no pricing terms of its own. |
unknown_item | 422 | The catalog has no medication or shipping option with that ID. |
email_failed | 502 | The invitation was saved, but Affinity could not send the invitation email. |
stripe_failed | 502 | Stripe refused a billing request from Affinity staff. |
upstream_error | 502 | The sign-in provider did not answer as expected. |
npi_registry_unavailable | 503 | The public NPI registry did not answer a name lookup within 5 seconds. |
pricing_unavailable | 503 | The catalog's prices are not synced yet. |