Add prescription to order
/v1/orders/{orderId}/prescriptionsRequires orders:write, Idempotency-Key and expectedRevision from the order being edited. Existing integrations may send expectedVersions instead; supply exactly one. Adds a complete prescription to an unsigned Order and returns all new versions. Omitted actor context defaults to the authenticated service account as a system actor. Patient and prescriber attribution stay fixed. Signed orders cannot be amended through this endpoint. Signing and submission require orders:sign through their separate endpoints.
Request example
Replace example values with your Test data. Check the field rules below before you send a request.
"<string>"curl -X POST 'https://api.affinityrx.com/v1/orders/{orderId}/prescriptions' \
-H "Authorization: Bearer $AFFINITY_API_KEY" \
-H 'Affinity-Version: 2026-09-28' \
-H 'Idempotency-Key: <Idempotency-Key>' \
-H 'Content-Type: application/json' \
--data @request.jsonResponse example
These examples show the body structure. Values can differ. Select a status code to see its response.
{
"revision": "<string>",
"object": "order_draft_update",
"externalOrderId": "<string>",
"metadata": "<string>",
"orderId": "ord_01j2y8m6jcc9tt24af5pw9x1bc",
"prescriptionId": "rx_01j2y8m6jcc9tt24af5pw9x1bc",
"prescriptions": "<string>"
}{
"code": "<string>",
"data": "<string>",
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"status": 400,
"title": "<string>",
"traceId": "<string>",
"type": "<string>"
}{
"code": "<string>",
"data": "<string>",
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"status": 401,
"title": "<string>",
"traceId": "<string>",
"type": "<string>"
}{
"code": "<string>",
"data": "<string>",
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"status": 403,
"title": "<string>",
"traceId": "<string>",
"type": "<string>"
}{
"code": "<string>",
"data": "<string>",
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"status": 404,
"title": "<string>",
"traceId": "<string>",
"type": "<string>"
}{
"code": "<string>",
"data": "<string>",
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"status": 409,
"title": "<string>",
"traceId": "<string>",
"type": "<string>"
}{
"code": "<string>",
"data": "<string>",
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"status": 422,
"title": "<string>",
"traceId": "<string>",
"type": "<string>"
}{
"code": "<string>",
"data": "<string>",
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"status": 429,
"title": "<string>",
"traceId": "<string>",
"type": "<string>"
}{
"code": "<string>",
"data": "<string>",
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"status": 503,
"title": "<string>",
"traceId": "<string>",
"type": "<string>"
}Implementation specification
Use these field types and limits to build your integration. Download the OpenAPI document for the complete contract.
Path parameters
orderIdstringrequiredPattern: ^ord_[0-7][0-9a-hjkmnp-tv-z]{25}$
Headers
Affinity-VersionstringSelects the HTTP API contract for this request only. When omitted, API-key requests use their service account’s stored version. Does not change the stored default.
Pin requests to 2026-09-28.
Idempotency-KeystringrequiredAffinity-Actor-IdstringRequired for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.
Affinity-Actor-TypestringUse user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.
Request body specification application/json
metadataobject | nullShow metadata fields
Any of · 1: object
Additional properties
Any of · 1: string
string
Maximum length: 500
Pattern: ^[^\p{Cs}]*$
Any of · 2: number
number
Any of · 3: boolean
boolean
Any of · 4: null
null
object
Any of · 2: null
null
practiceIdstringrequiredPattern: ^prac_[0-7][0-9a-hjkmnp-tv-z]{25}$
expectedRevisionstring | nullShow expectedRevision fields
Any of · 1: string
Opaque revision of the complete order prescription set. Send the revision you reviewed as expectedRevision; never replace it automatically after a conflict.
Pattern: ^rev_[a-f0-9]{64}$
Any of · 2: null
null
expectedVersionsobject[] | nullShow expectedVersions fields
Any of · 1: object[]
Array items · object
prescriptionIdstringrequiredPattern: ^rx_[0-7][0-9a-hjkmnp-tv-z]{25}$
versionintegerrequiredMinimum: 1
Any of · 2: null
null
prescriptionobjectrequiredNo additional properties
Show prescription fields
externalPrescriptionIdany | nullShow externalPrescriptionId fields
Any of · 1: any
All of · 1: any
any
Pattern: ^[^\p{Cc}\p{Cs}]*$
Any of · 2: null
null
clinicalobject | nullShow clinical fields
Any of · 1: object
compoundingReasonobject | nullShow compoundingReason fields
Any of · 1: object
categorystring | nullShow category fields
Any of · 1: string
string
Allowed: "alcohol_free", "drug_shortage", "commercial_product_discontinued", "modified_release", "inactive_ingredient_sensitivity", "inactive_ingredient_toxicity", "concentration_adjustment", "alternate_route", "dosage_form_unavailable", "flavor_adjustment", "tablet_burden", "patient_cannot_use_commercial_product", "no_approved_product_available", "no_rationale_required", "other_patient_specific_need"
Any of · 2: null
null
contextstring | nullShow context fields
Any of · 1: string
string
Any of · 2: null
null
Any of · 2: null
null
medicationReviewStatusstring | nullShow medicationReviewStatus fields
Any of · 1: string
string
Allowed: "not_reviewed", "none", "recorded"
Any of · 2: null
null
diagnosisReviewStatusstring | nullShow diagnosisReviewStatus fields
Any of · 1: string
string
Allowed: "not_reviewed", "none", "recorded"
Any of · 2: null
null
currentMedicationsstring[] | nullShow currentMedications fields
Any of · 1: string[]
Array items · string
string
Any of · 2: null
null
diagnosesobject[] | nullShow diagnoses fields
Any of · 1: object[]
Array items · object
codestringrequireddisplaystringrequiredAny of · 2: null
null
observationsobject[] | nullShow observations fields
Any of · 1: object[]
Array items · object
displaystringrequiredunitstringrequiredvaluenumber | stringrequiredShow value fields
Any of · 1: number
number
Greater than: 0
Any of · 2: string
string
Allowed: "Infinity", "-Infinity", "NaN"
Any of · 2: null
null
Any of · 2: null
null
pharmacyIdstring | nullShow pharmacyId fields
Any of · 1: string
string
Pattern: ^pharm_[0-7][0-9a-hjkmnp-tv-z]{25}$
Any of · 2: null
null
daysSupplyintegerrequiredMinimum: 1
Maximum: 365
dispensingobjectrequiredNo additional properties
Show dispensing fields
dispenseUponAcceptanceboolean | nullShow dispenseUponAcceptance fields
Any of · 1: boolean
boolean
Any of · 2: null
null
shippingOptionIdstring | nullShow shippingOptionId fields
Any of · 1: string
string
Pattern: ^shp_[0-7][0-9a-hjkmnp-tv-z]{25}$
Any of · 2: null
null
shippingAmountCentsinteger | nullReviewed customer shipping rate for the selected service. Preview supplies this value. Shared group rates must not be summed per prescription.
Show shippingAmountCents fields
Any of · 1: integer
integer
Minimum: 0
Any of · 2: null
null
shippingDestinationTypestring | nullShow shippingDestinationType fields
Any of · 1: string
string
Allowed: "patient"
Any of · 2: null
null
pharmacyNotesstring | nullShow pharmacyNotes fields
Any of · 1: string
string
Any of · 2: null
null
requestedFillDatestring | nullShow requestedFillDate fields
Any of · 1: string
string
Pattern: ^\d{4}-\d{2}-\d{2}$
Any of · 2: null
null
substitutionPermittedboolean | nullShow substitutionPermitted fields
Any of · 1: boolean
boolean
Any of · 2: null
null
directionsstringrequiredmedicationIdstringrequiredPattern: ^cat_[0-7][0-9a-hjkmnp-tv-z]{25}$
quantitynumber | stringrequiredShow quantity fields
Any of · 1: number
number
Maximum: 100000
Greater than: 0
Any of · 2: string
string
Allowed: "Infinity", "-Infinity", "NaN"
quantityUnitstringrequiredrefillsintegerrequiredMinimum: 0
Maximum: 99
structuredSigobject | nullShow structuredSig fields
Any of · 1: object
dosestringrequireddoseUnitstringrequireddurationstring | nullShow duration fields
Any of · 1: string
string
Any of · 2: null
null
frequencystringrequiredindicationstring | nullShow indication fields
Any of · 1: string
string
Any of · 2: null
null
maxDailyUsestring | nullShow maxDailyUse fields
Any of · 1: string
string
Any of · 2: null
null
prnboolean | nullShow prn fields
Any of · 1: boolean
boolean
Any of · 2: null
null
routestringrequiredtitrationSchedulestring | nullShow titrationSchedule fields
Any of · 1: string
string
Any of · 2: null
null
Any of · 2: null
null
All of · 1: any
One of · 1: any
any
One of · 2: any
any
Response specifications
200Successful response
application/json
revisionstringrequiredOpaque revision of the complete order prescription set. Send the revision you reviewed as expectedRevision; never replace it automatically after a conflict.
Pattern: ^rev_[a-f0-9]{64}$
objectstringrequiredAllowed: "order_draft_update"
externalOrderIdany | nullrequiredShow externalOrderId fields
Any of · 1: any
All of · 1: any
any
Pattern: ^[^\p{Cc}\p{Cs}]*$
Any of · 2: null
null
metadataany & anyrequiredShow metadata fields
All of · 1: any
any
All of · 2: any
any
Additional properties
Any of · 1: any & any
All of · 1: any
any
Pattern: ^[^\p{Cs}]*$
All of · 2: any
any
Maximum length: 500
Any of · 2: number
number
Any of · 3: boolean
boolean
Any of · 4: null
null
orderIdstringrequiredPattern: ^ord_[0-7][0-9a-hjkmnp-tv-z]{25}$
prescriptionIdstringrequiredPattern: ^rx_[0-7][0-9a-hjkmnp-tv-z]{25}$
prescriptionsany & anyrequiredShow prescriptions fields
Array items · object
idanyrequiredShow id fields
All of · 1: any
any
Pattern: ^rx_[0-7][0-9a-hjkmnp-tv-z]{25}$
externalPrescriptionIdany & any & any & any | nullrequiredShow externalPrescriptionId fields
Any of · 1: any & any & any & any
All of · 1: any
any
Minimum length: 1
All of · 2: any
any
Maximum length: 200
All of · 3: any
any
Pattern: \S
All of · 4: any
any
Pattern: ^[^\p{Cc}\p{Cs}]*$
Any of · 2: null
null
versionanyrequiredShow version fields
All of · 1: any
any
Minimum: 1
All of · 1: any
any
Minimum items: 1
All of · 2: any
any
Maximum items: 20
400HTTP 400
application/json
codestringrequireddataobjectdetailstringrequiredinstancestringrequiredrequestIdstringrequiredstatusintegerrequiredMinimum: 400
Maximum: 599
titlestringrequiredtraceIdstringtypestringrequiredFormat: uri
401Unauthorized
application/json
codestringrequireddataobjectdetailstringrequiredinstancestringrequiredrequestIdstringrequiredstatusintegerrequiredMinimum: 400
Maximum: 599
titlestringrequiredtraceIdstringtypestringrequiredFormat: uri
403Forbidden
application/json
codestringrequireddataobjectdetailstringrequiredinstancestringrequiredrequestIdstringrequiredstatusintegerrequiredMinimum: 400
Maximum: 599
titlestringrequiredtraceIdstringtypestringrequiredFormat: uri
404Not found
application/json
codestringrequireddataobjectdetailstringrequiredinstancestringrequiredrequestIdstringrequiredstatusintegerrequiredMinimum: 400
Maximum: 599
titlestringrequiredtraceIdstringtypestringrequiredFormat: uri
409Conflict
application/json
codestringrequireddataobjectdetailstringrequiredinstancestringrequiredrequestIdstringrequiredstatusintegerrequiredMinimum: 400
Maximum: 599
titlestringrequiredtraceIdstringtypestringrequiredFormat: uri
422Validation error
application/json
codestringrequireddataobjectdetailstringrequiredinstancestringrequiredrequestIdstringrequiredstatusintegerrequiredMinimum: 400
Maximum: 599
titlestringrequiredtraceIdstringtypestringrequiredFormat: uri
429Too many requests
application/json
codestringrequireddataobjectdetailstringrequiredinstancestringrequiredrequestIdstringrequiredstatusintegerrequiredMinimum: 400
Maximum: 599
titlestringrequiredtraceIdstringtypestringrequiredFormat: uri
503HTTP 503
application/json
codestringrequireddataobjectdetailstringrequiredinstancestringrequiredrequestIdstringrequiredstatusintegerrequiredMinimum: 400
Maximum: 599
titlestringrequiredtraceIdstringtypestringrequiredFormat: uri