curl --request POST \
--url https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"rxNumber": "<string>",
"fillDate": "2023-12-25",
"drugName": "<string>",
"billedAmount": "<string>",
"externalId": "<string>",
"ndc": "<string>",
"quantity": "<string>",
"daysSupply": 1825,
"prescriberName": "<string>",
"prescriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"claimDocumentId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"notes": "<string>"
}
'import requests
url = "https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills"
payload = {
"rxNumber": "<string>",
"fillDate": "2023-12-25",
"drugName": "<string>",
"billedAmount": "<string>",
"externalId": "<string>",
"ndc": "<string>",
"quantity": "<string>",
"daysSupply": 1825,
"prescriberName": "<string>",
"prescriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"claimDocumentId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"notes": "<string>"
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
rxNumber: '<string>',
fillDate: '2023-12-25',
drugName: '<string>',
billedAmount: '<string>',
externalId: '<string>',
ndc: '<string>',
quantity: '<string>',
daysSupply: 1825,
prescriberName: '<string>',
prescriptionId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
claimDocumentId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
notes: '<string>'
})
};
fetch('https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'rxNumber' => '<string>',
'fillDate' => '2023-12-25',
'drugName' => '<string>',
'billedAmount' => '<string>',
'externalId' => '<string>',
'ndc' => '<string>',
'quantity' => '<string>',
'daysSupply' => 1825,
'prescriberName' => '<string>',
'prescriptionId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'claimDocumentId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'notes' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills"
payload := strings.NewReader("{\n \"rxNumber\": \"<string>\",\n \"fillDate\": \"2023-12-25\",\n \"drugName\": \"<string>\",\n \"billedAmount\": \"<string>\",\n \"externalId\": \"<string>\",\n \"ndc\": \"<string>\",\n \"quantity\": \"<string>\",\n \"daysSupply\": 1825,\n \"prescriberName\": \"<string>\",\n \"prescriptionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"claimDocumentId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"notes\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"rxNumber\": \"<string>\",\n \"fillDate\": \"2023-12-25\",\n \"drugName\": \"<string>\",\n \"billedAmount\": \"<string>\",\n \"externalId\": \"<string>\",\n \"ndc\": \"<string>\",\n \"quantity\": \"<string>\",\n \"daysSupply\": 1825,\n \"prescriberName\": \"<string>\",\n \"prescriptionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"claimDocumentId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"notes\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"rxNumber\": \"<string>\",\n \"fillDate\": \"2023-12-25\",\n \"drugName\": \"<string>\",\n \"billedAmount\": \"<string>\",\n \"externalId\": \"<string>\",\n \"ndc\": \"<string>\",\n \"quantity\": \"<string>\",\n \"daysSupply\": 1825,\n \"prescriberName\": \"<string>\",\n \"prescriptionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"claimDocumentId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"notes\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"medCaseId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"medReferralId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"externalId": "<string>",
"rxNumber": "<string>",
"fillDate": "2023-12-25",
"ndc": "<string>",
"drugName": "<string>",
"quantity": "<string>",
"daysSupply": 1825,
"prescriberName": "<string>",
"billedAmount": "<string>",
"prescriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"claimDocumentId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"notes": "<string>",
"voidedAt": "2023-11-07T05:31:56Z",
"voidReason": "<string>",
"createdVia": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z",
"replayed": true
}
}{
"data": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"medCaseId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"medReferralId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"externalId": "<string>",
"rxNumber": "<string>",
"fillDate": "2023-12-25",
"ndc": "<string>",
"drugName": "<string>",
"quantity": "<string>",
"daysSupply": 1825,
"prescriberName": "<string>",
"billedAmount": "<string>",
"prescriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"claimDocumentId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"notes": "<string>",
"voidedAt": "2023-11-07T05:31:56Z",
"voidReason": "<string>",
"createdVia": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}Record a dispensed fill
Records a prescription the pharmacy dispensed and billed on this referral; billedAmount counts toward the balance. Requires a provider-scoped key (cxpp_) for a pharmacy practice at STANDARD tier, on the practice’s own referral. Firm keys receive 403 wrong_scope; a non-pharmacy practice receives 403 pharmacy_only; another practice’s referral is 404. Writes are accepted while the referral is accepted, in treatment, treatment complete, closed or withdrawn — payments often arrive after the firm closes the case — and refused with 409 referral_not_writable while sent, under review, rejected or archived. Restricted-access practices receive 403 restricted_access. Idempotent on externalId: 201 on create, 200 with meta.replayed=true on a replay of the same payload, 409 external_id_conflict (error.details.existingId) for the same externalId with a different payload. Compared after normalisation (money as 2-decimal strings, NDC hyphens removed, absent and null equal). A replay is compared with the record as it is now, so re-sending the original POST after any PATCH to that record returns 409 external_id_conflict; to recover, PATCH the record at error.details.existingId instead of re-posting. Referenced ids (prescriptionId, claimDocumentId, fillId, reversesTransactionId) are part of the compared payload, so a replay after the referenced record was deleted (its link cleared) also returns 409 external_id_conflict. Emits a pharmacy_fill.created webhook to the pharmacy.
curl --request POST \
--url https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"rxNumber": "<string>",
"fillDate": "2023-12-25",
"drugName": "<string>",
"billedAmount": "<string>",
"externalId": "<string>",
"ndc": "<string>",
"quantity": "<string>",
"daysSupply": 1825,
"prescriberName": "<string>",
"prescriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"claimDocumentId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"notes": "<string>"
}
'import requests
url = "https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills"
payload = {
"rxNumber": "<string>",
"fillDate": "2023-12-25",
"drugName": "<string>",
"billedAmount": "<string>",
"externalId": "<string>",
"ndc": "<string>",
"quantity": "<string>",
"daysSupply": 1825,
"prescriberName": "<string>",
"prescriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"claimDocumentId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"notes": "<string>"
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
rxNumber: '<string>',
fillDate: '2023-12-25',
drugName: '<string>',
billedAmount: '<string>',
externalId: '<string>',
ndc: '<string>',
quantity: '<string>',
daysSupply: 1825,
prescriberName: '<string>',
prescriptionId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
claimDocumentId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
notes: '<string>'
})
};
fetch('https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'rxNumber' => '<string>',
'fillDate' => '2023-12-25',
'drugName' => '<string>',
'billedAmount' => '<string>',
'externalId' => '<string>',
'ndc' => '<string>',
'quantity' => '<string>',
'daysSupply' => 1825,
'prescriberName' => '<string>',
'prescriptionId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'claimDocumentId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'notes' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills"
payload := strings.NewReader("{\n \"rxNumber\": \"<string>\",\n \"fillDate\": \"2023-12-25\",\n \"drugName\": \"<string>\",\n \"billedAmount\": \"<string>\",\n \"externalId\": \"<string>\",\n \"ndc\": \"<string>\",\n \"quantity\": \"<string>\",\n \"daysSupply\": 1825,\n \"prescriberName\": \"<string>\",\n \"prescriptionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"claimDocumentId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"notes\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"rxNumber\": \"<string>\",\n \"fillDate\": \"2023-12-25\",\n \"drugName\": \"<string>\",\n \"billedAmount\": \"<string>\",\n \"externalId\": \"<string>\",\n \"ndc\": \"<string>\",\n \"quantity\": \"<string>\",\n \"daysSupply\": 1825,\n \"prescriberName\": \"<string>\",\n \"prescriptionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"claimDocumentId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"notes\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.casexchange.com/api/public/v1/med-cases/{caseId}/referrals/{referralId}/pharmacy/fills")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"rxNumber\": \"<string>\",\n \"fillDate\": \"2023-12-25\",\n \"drugName\": \"<string>\",\n \"billedAmount\": \"<string>\",\n \"externalId\": \"<string>\",\n \"ndc\": \"<string>\",\n \"quantity\": \"<string>\",\n \"daysSupply\": 1825,\n \"prescriberName\": \"<string>\",\n \"prescriptionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"claimDocumentId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"notes\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"medCaseId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"medReferralId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"externalId": "<string>",
"rxNumber": "<string>",
"fillDate": "2023-12-25",
"ndc": "<string>",
"drugName": "<string>",
"quantity": "<string>",
"daysSupply": 1825,
"prescriberName": "<string>",
"billedAmount": "<string>",
"prescriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"claimDocumentId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"notes": "<string>",
"voidedAt": "2023-11-07T05:31:56Z",
"voidReason": "<string>",
"createdVia": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z",
"replayed": true
}
}{
"data": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"medCaseId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"medReferralId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"externalId": "<string>",
"rxNumber": "<string>",
"fillDate": "2023-12-25",
"ndc": "<string>",
"drugName": "<string>",
"quantity": "<string>",
"daysSupply": 1825,
"prescriberName": "<string>",
"billedAmount": "<string>",
"prescriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"claimDocumentId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"notes": "<string>",
"voidedAt": "2023-11-07T05:31:56Z",
"voidReason": "<string>",
"createdVia": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
},
"meta": {
"requestId": "req_f2dbe1d3f6ad4a7bb5b4c9f2",
"timestamp": "2023-11-07T05:31:56Z"
}
}Authorizations
Public API key: cxp_<hex> (firm-scoped) or cxpp_<hex> (provider-scoped). Required on every request.
Path Parameters
Med case UUID: medCaseId in the referral.* webhook payload, or the id from GET /med-cases.
Med referral UUID: the referral of this case to your pharmacy practice. Find it with GET /med-cases/{id}/referrals, or take it from the referral.* webhook payload.
Body
1 - 50YYYY-MM-DD, a real calendar date.
1 - 500Non-negative decimal string, e.g. "40.00".
^\d{1,10}(\.\d{1,2})?$Your system's id for this record (e.g. a PioneerRx event id). Unique per practice within each resource type (fills, transactions and snapshots each have their own namespace), across all of the practice's referrals and cases: it is not scoped to a referral, so do not reuse one id for two referrals. Re-sending the same externalId with the same payload returns the existing record (200, meta.replayed=true), even after the referral has moved to a status that no longer accepts new records; with a different payload, 409 external_id_conflict. A replay is compared with the record as it is now, so re-sending the original POST after any PATCH to that record returns 409 external_id_conflict; to recover, PATCH the record at error.details.existingId instead of re-posting. Referenced ids (prescriptionId, claimDocumentId, fillId, reversesTransactionId) are part of the compared payload, so a replay after the referenced record was deleted (its link cleared) also returns 409 external_id_conflict. Leading and trailing whitespace is trimmed. A POST without an externalId is accepted but never deduplicated, so always send one.
1 - 20011 digits; hyphens and spaces are accepted and removed.
Decimal string greater than 0, up to 3 fractional digits, e.g. "30" or "7.5".
^\d{1,9}(\.\d{1,3})?$0 <= x <= 3650300A prescription routed to your pharmacy on this case (GET /med-cases/{caseId}/prescriptions); otherwise 400 invalid_reference.
A document on this case that your practice can see — one your practice uploaded, or a firm upload the firm has not hidden; otherwise 400 invalid_reference.
2000Response
Replay: the externalId was already used with the same payload. The existing fill is returned, nothing is written, logged or emitted, and meta.replayed is true.

