Skip to main content
This recipe cancels an order you created with POST /api/v1/orders/cancel/{partner_reference}. A cancel that already happened answers 200 with already_cancelled true, so after a lost answer you simply send it again. After no answer, a 429 or a 5xx, it waits Retry-After, or 1, 2, 4, then 8 seconds with jitter, at most five times. A cancel is not a refund.

Prerequisites

  • MART_API_KEY: your API key, with the orders:write scope.
  • MART_API_BASE: https://sandbox.mart.ps while you build, https://mart.ps when you go live.
  • MART_PARTNER_REFERENCE: the reference you gave the order.
One runtime: cURL 7.84 or later with jq; Node 22.18 or later, which runs the .ts file as it is; Python 3.9 or later with httpx; PHP 7.4 or later with its curl extension; Go 1.22 or later; or Java 17 or later with Jackson (jackson-databind). Each file reads its variables from the environment and sets a timeout on every call. Run it on your own server: a browser or an app never holds the key.

Run the recipe

Verify the result

Run it twice for the same order:
The second run prints already cancelled: true: nothing changed. status id is the status Mart moved the order to; treat it as opaque.

Troubleshooting

Every other code is in the error catalog.