Update redemption instructions or voucher details
Change the redemption instructions, voucher code or customer details saved on one redemption order in your community.
- Method
- PATCH
- Path
https://api.returning.ai / v1/ purchase-histories/ {purchaseHistoryID} - Permission
- purchase-history
- Retries
- No Idempotency-Key; read the order before retrying
When to use this
- You fulfil a reward by hand and need to give the trader a new voucher code or expiry date.
- The instructions a trader sees for one order need correcting, such as where to collect a prize.
- A trader asks you to fix the delivery address or an order-form answer on their order.
Authentication#
- Header
Authorization: Bearer <API_KEY>- Permission
- purchase-historyShown in the dashboard as “Purchase History”
Send a Community API key with the purchase-history permission. The key decides the community, so you can only change orders in that community. Keep the key on your server.
Behaviour#
There are two kinds of change, and each request makes one of them.
- Instructions and voucher. Send
redemptionInstructions, the pairvoucherCodeandvoucherExpiryDate, or all three. New instructions apply to this order only; the product keeps its own. Setting instructions also refreshes the order's saved copy of the product (name, description, image and price) from the current product, and fails with404if the product was deleted. A new voucher code changes the voucher record itself, and must not match another voucher on the same product. - Customer details. Send
changeswithuserInfo,customOptionsor both. Only values that differ from what is saved count. Each successful update adds an entry to the order's change history, andmeta.auditEventIdidentifies it.
The order's status, price and coins don't change, and the trader isn't emailed or notified. The latest update wins if two arrive together.
Request#
Path parameters#
ORD...) from redemptionId in the order lists. The order's internal _id also works.RuleOrder ID in your community
EgORD20269268300418273
Headers#
Body#
Send a JSON object with at least one field. Fields this endpoint doesn't take are rejected, not ignored. Text values are trimmed. voucherExpiryDate is a date only, in DD/MM/YYYY; the voucher expires at the start of that day, midnight UTC, so send the day after if it should last through a date.
Rule1-10,000 chars, not blank; trimmed
Eg"Your $25 credit is added to your live trading account within 2 business days."
voucherExpiryDate.Rule1-512 chars, not blank; trimmed; unique within the product
Eg"TC25-8R5N-3C1Y"
voucherCode. Saved as the start of that day, midnight UTC.RuleDD/MM/YYYY, a real date
Eg"31/12/2026"
userInfo or customOptions, and no other top-level field.firstName, lastName, phonePrefix, phone, country, city, state, address, postalCode. Only state can be blank. Email can't be changed.name or _id, never both._id instead if two fields share a name.Eg"Account number"
Eg"<brokerCustomerId>"
curl --request PATCH \
--url https://api.returning.ai/v1/purchase-histories/ORD20269268300418273 \
--header 'Authorization: Bearer <API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"redemptionInstructions": "Your $25 credit is added to your live trading account within 2 business days.",
"voucherCode": "TC25-8R5N-3C1Y",
"voucherExpiryDate": "31/12/2026"
}'
Response#
A 200 returns the whole order in data, including the voucher code the trader sees. Branch on the HTTP status and meta.code, never on message.
Eg{ ... }
Rulesuccess
Eg200
RulePURCHASE_HISTORY_UPDATED
changes updates.Eg"Update purchase history success."
Eg{ ... }
Eg"66f000000000000000000401"
ORD...).Eg"ORD20269268300418273"
Eg"66f000000000000000000010"
Eg"<userObjectId>"
Eg"TC25-8R5N-3C1Y"
RuleDate-time
Eg"2026-12-31T00:00:00.000Z"
Eg{ ... }
Eg"66f000000000000000000502"
Eg"TC25-8R5N-3C1Y"
Ruleactive, redeemed or expired
Eg"redeemed"
RuleDate-time
Eg"2026-12-31T00:00:00.000Z"
redemptionInstructions. null when the product no longer exists and the order has no saved copy.Eg{ ... }
Eg"66f000000000000000000101"
Eg"$25 Trading Credit"
Eg"Your $25 credit is added to your live trading account within 2 business days."
username, name, email and any address fields._id, name and value. Empty when the product has no form.oldStatusName, newStatusName, remark and createdAt. Present once the status has changed.RuleDate-time
Eg"2026-09-26T08:30:00.000Z"
RuleDate-time
Eg"2026-09-27T10:15:00.000Z"
{
"meta": {
"status": "success",
"statusCode": 200,
"code": "PURCHASE_HISTORY_UPDATED"
},
"message": "Update purchase history success.",
"data": {
"_id": "66f000000000000000000401",
"purchaseID": "ORD20269268300418273",
"communityID": "66f000000000000000000010",
"userID": "<userObjectId>",
"status": "Completed",
"purchaseStatusID": "66f000000000000000000405",
"price": 500,
"quantity": 1,
"voucherCode": "TC25-8R5N-3C1Y",
"voucherExpiryDate": "2026-12-31T00:00:00.000Z",
"voucher": {
"_id": "66f000000000000000000502",
"code": "TC25-8R5N-3C1Y",
"status": "redeemed",
"expiryDate": "2026-12-31T00:00:00.000Z"
},
"product": {
"_id": "66f000000000000000000101",
"name": "$25 Trading Credit",
"description": "<p>Redeem 500 coins for a $25 trading credit on your live account.</p>",
"image": "https://cdn.example.com/store/trading-credit-25.png" ,
"price": 500,
"type": "voucher",
"redemptionInstructions": "Your $25 credit is added to your live trading account within 2 business days."
},
"userInfo": {
"username": "sample_trader",
"name": "Sample Trader",
"email": "trader@example.com"
},
"customOptions": [],
"purchasedDate": "2026-09-26T08:30:00.000Z",
"latestStatusHistory": {
"oldStatusName": "New Purchase",
"newStatusName": "Completed",
"remark": "Updated by API",
"createdAt": "2026-09-26T09:15:00.000Z"
},
"createdAt": "2026-09-26T08:30:00.000Z",
"updatedAt": "2026-09-27T10:15:00.000Z"
}
}
Errors#
Every error carries its code in meta.code, with the reason in detail, except a 400 for a body of the wrong shape, which has no code and puts the reason in detail.body.
Fix the request05
meta.code. detail.body says which: an empty body, a field this endpoint doesn't take, both kinds of change in one request, or a form answer with both or neither of name and _id. Nothing was changed.VALIDATION_FAILEDFix the requestdetail says which: for example a voucher code sent without its expiry date, a date not in DD/MM/YYYY, a blank value, an unknown form field name, or No purchase history details changed when every value already matches.AUTH_API_KEY_REQUIREDFix the requestAuthorization: Bearer <API_KEY>.AUTH_API_KEY_INVALIDFix the requestAUTH_PERMISSION_REQUIREDFix the requestpurchase-history. Add the permission in Settings > Integration > API Keys.Fix the data02
STORE_RESOURCE_NOT_FOUNDFix the datadetail says which: Purchase history not found (check the ORD... order ID from the order lists), or Product not found for purchaseHistory (the product was deleted, so instructions can't be set; voucher and customer changes still work).STORE_RESOURCE_CONFLICTFix the dataRetry with backoff03
STORE_DEPENDENCY_UNAVAILABLERetry with backoffINTERNAL_ERRORRetry with backoffAUTH_API_KEY_VALIDATION_FAILEDRetry with backoff{
"meta": {
"status": "error",
"statusCode": 400,
"code": "VALIDATION_FAILED"
},
"message": "Validation failed",
"detail": {
"voucherExpiryDate": "voucherExpiryDate must be a valid date in DD/MM/YYYY format"
},
"solution": "Please check the request and try again"
}