Skip to content

Errors

Problem documents, field issues and recovery instructions for every error code.

Updated

An error response is a flat problem document (RFC 9457) with the content type application/problem+json. All members are at the top level.

FieldMeaning
codeThe error code, in lowercase snake_case. Branch on this value.
statusThe HTTP status. It is the same as the response status.
titleA short name of the error.
detailA sentence for a person about this failure. The text can change. Do not branch on it.
typeThe URL of the page for the code on this site.
instanceThe request path, without the query string.
requestIdThe ID of the request. Give it to Affinity when you report a problem.
issuesField details for 400 invalid_request, path IDs of another resource type with 404 not_found, and some 422 responses.
dataOptional recovery fields, such as practiceId or orderId on duplicate conflicts.
traceIdOptional. 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:

FieldMeaning
codeWhat is wrong with the field, for example invalid_value, required or restricted_state.
fieldThe place of the value as a string, for example prescriptions[0].compoundingReason.
pathThe same place as an array, for example ["prescriptions", 0, "compoundingReason"].
messageA 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_progress or 429, wait before you retry. Repeat the unchanged request with the same Idempotency-Key, when present.
  • For other 4xx errors, follow the code's recovery instructions. Change the request or resolve the reported problem before you retry.
  • Retry 500 and 503 with backoff.
  • For practice creation or updates, order creation or cancellation, webhook mutations and feedback, retry with the same Idempotency-Key and the same body. Affinity does not repeat the action. Order creation returns 200 with 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 returns 404 after the endpoint is deleted. Other keyed requests return the first response.

Codes for API key requests

CodeStatusMeaning
invalid_cursor400The list cursor belongs to another list or to other filters.
invalid_path400The 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_request400A 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_version400The Affinity-Version header is missing or names an unknown version.
unauthorized401The API key or the session is missing, wrong, revoked or expired.
dashboard_only403API keys cannot call this route. You manage it in the Affinity app.
forbidden403Your 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_required403Only a Live API key can turn a practice's Live access on or off.
live_mode_required403The 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_enabled403Live 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_disabled403Your platform does not have Live access, so it cannot give Live access to a practice.
platform_only403Only a platform manages practices.
staff_only403The request requires Affinity staff access, including orders with the reserved pharmacy verification note.
not_found404The record or route does not exist, belongs to another organization or mode, or the path ID names another resource type.
method_not_allowed405The path exists, but not with this HTTP method.
cancel_refused409The cancel request failed or the pharmacy refused it. The order keeps its status.
cannot_cancel409The order is shipped, delivered or failed, so it cannot be cancelled.
idempotency_key_reused409The Idempotency-Key was used before with a different request body, or its first result is not available.
invalid_transition409The order cannot change that way from its current status.
order_already_exists409This practice already has an order with the same externalOrderId in this mode.
order_changed409The order changed while the request ran.
payment_method_required409A 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_exists409Another active practice of this platform already uses this externalId.
request_in_progress409The first request with this Idempotency-Key has not finished.
payload_too_large413The 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_type415The request body is not JSON.
invalid_address422The practice has no address, and the address update omits required fields.
invalid_order422The 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_text422PerfectRx 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_url422The URL supplied to create or update a webhook endpoint fails public HTTPS validation or host resolution.
medication_not_visible422A 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_required422The practice update sends null for address or phone. Pharmacies need both on every order, so a practice keeps them.
too_many_webhook_endpoints422The organization has 16 webhook endpoints in this mode.
rate_limit_exceeded429Too 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_error500The API could not complete the request because of an unexpected error.
billing_unavailable503Billing is not available now.
service_unavailable503The API or a service that it needs is not available now.

Codes in the Affinity app only

CodeStatusMeaning
invalid_mode400A dashboard request sent no Affinity-Mode, or a value other than test or live.
cross_site_request403A write with a session cookie did not come from an Affinity app.
named_staff_only403Only Dawson or Tim can apply or reject a price change.
npi_required403The signed-in person has no NPI on their profile, so they cannot sign as themselves.
platform_managed403Only the practice's platform can delete this practice.
prescriber_name_required403The signed-in member has no valid first and last name, so they cannot sign an order.
signed_in_user_changed403A dashboard page wrote for a person who is no longer signed in: someone else signed in from another tab of the same browser.
account_deactivated409Staff tried to add a person whose account is deactivated. They cannot sign in.
billing_managed_by_platform409The practice's platform pays for it, so the practice has no billing portal.
billing_payer_busy409Another billing action is running for this organization.
billing_payer_lease_lost409A billing action stopped before it finished because it lost its lock.
cannot_dismiss409The order is not failed, so it cannot be dismissed from Needs attention.
conflict409The account change conflicts with the current state, for example an email that another account uses.
controlled_not_sendable409The order names a controlled medication, which cannot be ordered yet. Nothing was charged or sent.
invoice_incomplete409Orders are still being added to this draft, so it can't be approved yet.
invoice_not_finalized409Only an invoice approved without email, and not yet paid, void or emailed, can be emailed.
invoice_total_mismatch409The draft's total in Stripe is not what its orders are billed, so it is not finalized.
last_admin409An organization needs at least one admin.
member_changed409The person changed after the screen loaded: an invited person joined, or a removed member got a new invitation. Nothing was removed.
not_a_draft409The invoice status does not permit the requested action.
npi_in_use409Another account has this NPI. One NPI belongs to one person.
order_already_billable409The full order is already marked billable or linked to an invoice.
order_at_pharmacy409The 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_held409A held order ends failed or cancelled only from its held panel.
order_may_be_at_pharmacy409A 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_held409The order is not a held Live submission.
order_not_sent409Affinity has not sent the order to the pharmacy, so staff cannot set it processing, shipped or delivered.
order_not_shipped409The pharmacy has not shipped the order, so its shipping option is still the one Affinity sends.
order_rejected_by_pharmacy409The pharmacy rejected the held order after it received it, so Resend cannot send it.
orders_in_progress409The organization has Live orders that a pharmacy is still filling. Test orders do not block deletion.
organization_archived409The organization is deleted, so its prices do not change.
patient_changed409The patient changed after the dashboard read it, so the dashboard order was not signed. Nothing was saved or sent.
payment_declined409The payment for this order failed, so the order was not sent to the pharmacy. It waits for Affinity staff.
payment_method_pending409Stripe did not finish saving the payment method, so it is not the default payment method yet.
pharmacy_cancels_by_phone409The pharmacy has no cancel call, so Resend cannot send the held cancel. It cancels by phone only.
price_change_decided409The price change was applied, rejected or replaced before.
price_change_preview_changed409The prices that the change moves changed after the page loaded.
price_change_stale409The organization got new pricing terms after this change was proposed.
price_changed409A reviewed prescription or shipping charge changed before the app signed the order.
price_review_required409The app's new order request did not include the reviewed prices.
pricing_busy409Another price change or a catalog update is in progress.
review_not_available409Only a platform's or an independent practice's Live orders are reviewed by Affinity staff.
reward_points_insufficient409The practice does not have the Affinity Rewards points that this order uses. Points are for Live orders only. No order was created.
shipment_not_billable409The order is not a failed Live order eligible for Affinity billing.
billing_email_required422The invoice would be emailed, but the payer has no Stripe billing email.
confirmation_required422A price change sets a price above the customer's tier price, and the staff member did not confirm it.
credit_refused422Stripe refused the account credit, so no credit was added.
invalid_failure_reason422A staff failure reason must contain 1 to 500 characters.
invalid_note422A staff note must contain 1 to 500 characters.
invalid_npi422The NPI is not a valid 10-digit NPI.
invalid_patient422The dashboard tried to change the first or last name of a patient whose name the pharmacy keeps. Nothing was saved.
invalid_price422A price is not dollars with at most two decimals.
invalid_profile_text422address.line2 on PATCH /v1/me is see notes, TBD or unknown. Those values are not a suite.
invalid_shipping_option422The shipping option does not belong to the order's pharmacy.
invalid_terms422The 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_total422The invoice credit makes the draft total negative.
invoice_too_many_items422The draft would list more items than Stripe allows on one invoice (250).
no_change422The proposed pricing terms are the terms that the organization pays now.
tier_inherited422A practice under a platform pays its platform's prices, so it has no pricing terms of its own.
unknown_item422The catalog has no medication or shipping option with that ID.
email_failed502The invitation was saved, but Affinity could not send the invitation email.
stripe_failed502Stripe refused a billing request from Affinity staff.
upstream_error502The sign-in provider did not answer as expected.
npi_registry_unavailable503The public NPI registry did not answer a name lookup within 5 seconds.
pricing_unavailable503The catalog's prices are not synced yet.

Send feedback

Don't include patient information.

Type to search…

↑↓ navigate ↵ select Esc close