curl --request POST \
--url https://sandbox-api.instockrx.com/marketplace-listings/{id}/cancel \
--header 'Content-Type: application/json' \
--header 'X-InStockRx-Api-Key: <api-key>' \
--data '
{
"cancellationMessage": "<string>"
}
'const options = {
method: 'POST',
headers: {'X-InStockRx-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({cancellationMessage: '<string>'})
};
fetch('https://sandbox-api.instockrx.com/marketplace-listings/{id}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://sandbox-api.instockrx.com/marketplace-listings/{id}/cancel"
payload = { "cancellationMessage": "<string>" }
headers = {
"X-InStockRx-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "Pending",
"nationalDrugCode": "<string>",
"sellerPharmacyId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"deliveryStatus": "Unknown",
"paymentStatus": "NotInitiated",
"nationalDrugCodeNormalized": "<string>",
"labelerName": "<string>",
"packageName": "<string>",
"drugPackageForm": "<string>",
"drugPackageStrength": "<string>",
"quantityUnitQualifier": "<string>",
"price": "42.50",
"pricePerQuantity": "42.50",
"quantity": "1",
"inventoryQuantity": "1",
"expirationDate": "2023-12-25",
"lotNumber": "<string>",
"gtin": "<string>",
"serialNumber": "<string>",
"fullPackage": true,
"originalPackage": true,
"sealedPackage": true,
"tornPackageLabel": true,
"additionalPackageNotes": "<string>",
"branded": true,
"generic": true,
"sellerPharmacyName": "<string>",
"sellerPharmacyDBA": "<string>",
"sellerPharmacyNpi": "1234567890",
"sellerPharmacyPhone": "<string>",
"sellerPharmacyAddress": {
"line1": "<string>",
"line2": "<string>",
"city": "<string>",
"stateAcronym": "<string>",
"postalCode": "<string>"
},
"buyerPharmacyName": "<string>",
"buyingPharmacyName": "<string>",
"buyingPharmacyDBA": "<string>",
"buyingPharmacyNpi": "1234567890",
"buyingPharmacyPhone": "<string>",
"buyingPharmacyAddress": {
"line1": "<string>",
"line2": "<string>",
"city": "<string>",
"stateAcronym": "<string>",
"postalCode": "<string>"
},
"buyersMessage": "<string>",
"listingDate": "2023-11-07T05:31:56Z",
"soldDate": "2023-11-07T05:31:56Z",
"shippingConfirmDate": "2023-11-07T05:31:56Z",
"shippingReceivedConfirmDate": "2023-11-07T05:31:56Z",
"paymentConfirmedDate": "2023-11-07T05:31:56Z",
"shipByDate": "2023-12-25",
"cancelledDate": "2023-11-07T05:31:56Z",
"cancellationReason": "SellerCancelled",
"cancellationDescription": "<string>",
"receivedDetails": {
"gtin": "<string>",
"serialNumber": "<string>",
"lotNumber": "<string>",
"expirationDate": "2023-12-25",
"nationalDrugCode": "<string>"
},
"receivedDetailsMatch": true,
"receivedDetailsConfirmationType": "NotChecked"
}{
"type": "https://api.instockrx.com/problems/listing-not-available",
"title": "<string>",
"status": 349,
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"errors": [
{
"field": "<string>",
"code": "<string>",
"message": "<string>"
}
]
}{
"type": "https://api.instockrx.com/problems/listing-not-available",
"title": "<string>",
"status": 349,
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"errors": [
{
"field": "<string>",
"code": "<string>",
"message": "<string>"
}
]
}{
"type": "https://api.instockrx.com/problems/listing-not-available",
"title": "<string>",
"status": 349,
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"errors": [
{
"field": "<string>",
"code": "<string>",
"message": "<string>"
}
]
}{
"type": "https://api.instockrx.com/problems/listing-not-available",
"title": "<string>",
"status": 349,
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"errors": [
{
"field": "<string>",
"code": "<string>",
"message": "<string>"
}
]
}Cancel a marketplace listing
Scope: listings:write.
Cancels a purchased listing. The acting pharmacy (X-Pharmacy-Id) must be either
the seller or the buyer of this listing; any other pharmacy gets 404.
The reason must match your side
cancellationReason accepts only SellerCancelled or BuyerCancelled — the
auto-trigger values are reserved for system use — and it must match the side you are
acting as. A seller sends SellerCancelled, a buyer sends BuyerCancelled. Either
mistake is 400 invalid-cancellation-reason.
cancellationMessage is optional here. When you omit it the server records
Cancelled via API v2 ({reason}).
When a cancel is allowed
The rules are the same whichever side you are.
| Listing state | Cancel |
|---|---|
| Purchased, not yet shipped | Allowed |
| Shipped on an InStockRx label | Allowed until the carrier accepts the parcel |
| Shipped, buyer arranged their own shipping | Refused |
| Reported not received | Refused |
| Receipt confirmed | Refused |
| Already cancelled | Refused |
A buyer can cancel after the seller has marked the listing shipped. On an InStockRx
label the cut-off is the carrier’s first scan rather than the seller confirming
shipment: the parcel counts as accepted once its delivery status is anything other than
unknown, pre_transit, cancelled or error. Where the buyer arranged their own
shipping, confirming shipment still closes the window.
A state refusal is a 400 titled One or more validation errors occurred., carrying one
entry in errors per failed rule — for example marketplaceListing.deliveryStatus with
Marketplace listing can not be cancelled - the carrier has already accepted this shipment.
Auto-relist
A BuyerCancelled cancel on a listing that is still Purchased — not yet shipped — and
whose drug has not expired makes the backend relist the item under the same seller.
This is best-effort. It is skipped silently when the seller may not list at that moment (probation, class-of-trade approval pending, a selling or state partial-listing restriction, missing cold-chain certification, or licences not on file), or when the relisted item fails validation. Nothing in the response tells you which happened.
A buyer cancel after the listing was marked shipped never relists. The seller has to list the item again themselves.
Events
marketplace_listing.cancelled fires on every cancel this endpoint performs, including
a buyer cancel after shipment.
curl --request POST \
--url https://sandbox-api.instockrx.com/marketplace-listings/{id}/cancel \
--header 'Content-Type: application/json' \
--header 'X-InStockRx-Api-Key: <api-key>' \
--data '
{
"cancellationMessage": "<string>"
}
'const options = {
method: 'POST',
headers: {'X-InStockRx-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({cancellationMessage: '<string>'})
};
fetch('https://sandbox-api.instockrx.com/marketplace-listings/{id}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://sandbox-api.instockrx.com/marketplace-listings/{id}/cancel"
payload = { "cancellationMessage": "<string>" }
headers = {
"X-InStockRx-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "Pending",
"nationalDrugCode": "<string>",
"sellerPharmacyId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"deliveryStatus": "Unknown",
"paymentStatus": "NotInitiated",
"nationalDrugCodeNormalized": "<string>",
"labelerName": "<string>",
"packageName": "<string>",
"drugPackageForm": "<string>",
"drugPackageStrength": "<string>",
"quantityUnitQualifier": "<string>",
"price": "42.50",
"pricePerQuantity": "42.50",
"quantity": "1",
"inventoryQuantity": "1",
"expirationDate": "2023-12-25",
"lotNumber": "<string>",
"gtin": "<string>",
"serialNumber": "<string>",
"fullPackage": true,
"originalPackage": true,
"sealedPackage": true,
"tornPackageLabel": true,
"additionalPackageNotes": "<string>",
"branded": true,
"generic": true,
"sellerPharmacyName": "<string>",
"sellerPharmacyDBA": "<string>",
"sellerPharmacyNpi": "1234567890",
"sellerPharmacyPhone": "<string>",
"sellerPharmacyAddress": {
"line1": "<string>",
"line2": "<string>",
"city": "<string>",
"stateAcronym": "<string>",
"postalCode": "<string>"
},
"buyerPharmacyName": "<string>",
"buyingPharmacyName": "<string>",
"buyingPharmacyDBA": "<string>",
"buyingPharmacyNpi": "1234567890",
"buyingPharmacyPhone": "<string>",
"buyingPharmacyAddress": {
"line1": "<string>",
"line2": "<string>",
"city": "<string>",
"stateAcronym": "<string>",
"postalCode": "<string>"
},
"buyersMessage": "<string>",
"listingDate": "2023-11-07T05:31:56Z",
"soldDate": "2023-11-07T05:31:56Z",
"shippingConfirmDate": "2023-11-07T05:31:56Z",
"shippingReceivedConfirmDate": "2023-11-07T05:31:56Z",
"paymentConfirmedDate": "2023-11-07T05:31:56Z",
"shipByDate": "2023-12-25",
"cancelledDate": "2023-11-07T05:31:56Z",
"cancellationReason": "SellerCancelled",
"cancellationDescription": "<string>",
"receivedDetails": {
"gtin": "<string>",
"serialNumber": "<string>",
"lotNumber": "<string>",
"expirationDate": "2023-12-25",
"nationalDrugCode": "<string>"
},
"receivedDetailsMatch": true,
"receivedDetailsConfirmationType": "NotChecked"
}{
"type": "https://api.instockrx.com/problems/listing-not-available",
"title": "<string>",
"status": 349,
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"errors": [
{
"field": "<string>",
"code": "<string>",
"message": "<string>"
}
]
}{
"type": "https://api.instockrx.com/problems/listing-not-available",
"title": "<string>",
"status": 349,
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"errors": [
{
"field": "<string>",
"code": "<string>",
"message": "<string>"
}
]
}{
"type": "https://api.instockrx.com/problems/listing-not-available",
"title": "<string>",
"status": 349,
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"errors": [
{
"field": "<string>",
"code": "<string>",
"message": "<string>"
}
]
}{
"type": "https://api.instockrx.com/problems/listing-not-available",
"title": "<string>",
"status": 349,
"detail": "<string>",
"instance": "<string>",
"requestId": "<string>",
"errors": [
{
"field": "<string>",
"code": "<string>",
"message": "<string>"
}
]
}Authorizations
Headers
Which pharmacy in your group you are acting as. Required whenever your group holds more than one pharmacy — omitting it is then 400 missing-pharmacy-context. With exactly one pharmacy it may be omitted, but send it anyway: the call starts failing the day a second pharmacy is added.
Body
Must be SellerCancelled when you are acting as the seller and
BuyerCancelled when you are acting as the buyer. The auto-trigger values
of MarketplaceListingCancellationReason are server-only. Supplying one of
those, or the other side's reason, is 400 invalid-cancellation-reason.
SellerCancelled, BuyerCancelled Response
OK
Lifecycle of a marketplace listing. V1 values 3 (PaymentConfirmed) and
4 (SaleConfirmed) are commented out in C# and excluded here.
The wire value ShippingReceivedNotConfirmed corresponds to the C#
member ShippingNotReceived (overridden via [EnumMember(Value=…)]).
Pending, Purchased, Cancelled, ShippingConfirmed, ShippingReceivedConfirmed, ShippingReceivedNotConfirmed, Paused Where a listing's payment has got to. Confirmed against
Inview.Domain/Enum/MarketplaceListingPaymentStatus.cs; the live document never
emits this enum, because it appears only on responses, so the drift check cannot
confirm it and a reader has to.
NotInitiated, Pending, PaymentConfirmed, PaymentSentToSeller, SellerReceivedPayment, Refunded, FailedDueToInsufficientFunds, Cancelled NPI as a fixed-width 10-digit string. v2 treats an NPI as an opaque identifier
rather than a number, consistent with how it handles NDC, GTIN and other
healthcare identifiers. CMS-issued NPIs always start with 1 or 2, so
leading-zero NPIs do not arise in practice, but string typing rules out the
broader class of integer-identifier truncation bugs that v1 was open to.
^\d{10}$"1234567890"
"2987654321"
NPI as a fixed-width 10-digit string. v2 treats an NPI as an opaque identifier
rather than a number, consistent with how it handles NDC, GTIN and other
healthcare identifiers. CMS-issued NPIs always start with 1 or 2, so
leading-zero NPIs do not arise in practice, but string typing rules out the
broader class of integer-identifier truncation bugs that v1 was open to.
^\d{10}$"1234567890"
"2987654321"
On reads, any of the eight values may appear — ReturnCompleted when a completed
return cancelled the sale, ShipByDateExpired when the seller missed the ship-by
date, and DuplicateOfAcceptedCashOffer when the listing was cancelled as a
duplicate of a cash offer that had already been accepted, and AdminRefund when an
InStockRx admin refunded the order after the seller had already been paid.
On writes (POST /marketplace-listings/{id}/cancel) only SellerCancelled and
BuyerCancelled are accepted, and the one you send must match the side you are
acting as: a seller sends SellerCancelled, a buyer sends BuyerCancelled. The
auto-trigger values are reserved for system use. Anything else is
400 invalid-cancellation-reason.
Choosing the right value matters beyond bookkeeping: BuyerCancelled on a listing
that is still Purchased makes the backend auto-relist the item under the same
seller. A seller-initiated cancel mislabelled as BuyerCancelled would spawn an
unwanted replacement listing. After the listing is marked shipped no cancel
relists, whichever reason is used.
SellerCancelled, PharmacyInventoryQuantityAutoTrigger, AutomaticDrugExpired, BuyerCancelled, ReturnCompleted, ShipByDateExpired, DuplicateOfAcceptedCashOffer, AdminRefund Server-computed comparison of receivedDetails against the
seller-declared pedigree on the listing. true if every field the
buyer supplied agreed with the listing; false if any disagreed;
null if no comparison was performed (no receivedDetails
supplied or confirmationType was NotChecked / Skipped).
Drives whether the seller earns a positive rating bump on receipt.