> This is Payabli documentation. For a complete page index, fetch https://docs.payabli.com/llms.txt — append .md to any page URL for lightweight markdown. For section-level indexes, query parameters, and other AI-optimized access methods, see https://docs.payabli.com/ai-agents.md

# Cancel device order

POST https://api-sandbox.payabli.com/api/DeviceOrder/{orderNumber}/cancel
Content-Type: application/json

Cancels a device order that's still `Placed`, meaning it isn't paid
yet. For any other status, this endpoint returns `409`.

To cancel an order that's already paid, contact Payabli. Payabli
reverses the charge before it cancels a paid order. If Payabli can't
reverse the charge, the order stays `Paid`.

This endpoint requires the `deviceorder_update` permission.


Reference: https://docs.payabli.com/developers/api-reference/device-orders/cancel-device-order

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.
- `requestToken` header (required) — Long-lived API token sent in the `requestToken` header. See [API token authentication](/developers/api-tokens).

## Servers

- `https://api-sandbox.payabli.com/api` (Sandbox, default)
- `https://api.payabli.com/api` (Production)

## Request

### Path parameters

- `orderNumber` (string, required) — The order number.

### Body (application/json)

This endpoint expects a DeviceOrderCancelRequest.

- `reason` (string, optional) — An optional reason for canceling the order.

## Response

### 200

Success

- `responseText` (string, required) — `Success` when the request succeeds.
- `responseData` (DeviceOrder, required) — A device order.
- `responseCode` (integer, optional) — Code for the response. Learn more in [API Response Codes](/developers/api-reference/api-responses).
- `pageIdentifier` (string, optional) — Auxiliary validation used internally by payment pages and components.
- `roomId` (long, optional) — Field not in use on this endpoint. It always returns `0`.
- `isSuccess` (boolean, optional) — Boolean indicating whether the operation was successful. A `true` value indicates success. A `false` value indicates failure.

## Errors

### 401 Unauthorized Error

Unauthorized request.

- `isSuccess` (boolean, required) — Always `false` for error responses.
- `responseText` (string, required) — Error text describing what went wrong.
- `responseCode` (integer, optional) — Code for the response. Learn more in [API Response Codes](/developers/api-reference/api-responses).
- `responseData` (PayabliErrorBodyResponseData, optional) — Object with detailed error context.

### 404 Not Found Error

The requested resource wasn't found.

- `isSuccess` (boolean, required) — Always `false` for error responses.
- `responseText` (string, required) — Error text describing what went wrong.
- `responseCode` (integer, optional) — Code for the response. Learn more in [API Response Codes](/developers/api-reference/api-responses).
- `responseData` (PayabliErrorBodyResponseData, optional) — Object with detailed error context.

### 409 Conflict Error

The order can't be canceled from its current status. Read the order again and check `allowedNextStates`.

- `isSuccess` (boolean, required) — Always `false` for error responses.
- `responseText` (string, required) — Error text describing what went wrong.
- `responseCode` (integer, optional) — Code for the response. Learn more in [API Response Codes](/developers/api-reference/api-responses).
- `responseData` (PayabliErrorBodyResponseData, optional) — Object with detailed error context.

### 500 Internal Server Error

Internal server error.

- `isSuccess` (boolean, required) — Always `false` for error responses.
- `responseText` (string, required) — Error text describing what went wrong.
- `responseCode` (integer, optional) — Code for the response. Learn more in [API Response Codes](/developers/api-reference/api-responses).
- `responseData` (PayabliErrorBodyResponseData, optional) — Object with detailed error context.

## Types

### DeviceOrder

A device order.

- `id` (long, required) — The order's internal ID.
- `orderNumber` (string, required) — The order number. Use it in the path of the other device order endpoints.
- `status` (enum, required) — The order's status. - `Placed`: The order was placed. A `PayNow` order stays `Placed` until it's paid. - `Paid`: The `PayNow` order was paid. - `Initiated`: Payabli started fulfilling the order. - `Dispatched`: Payabli shipped the order. - `Delivered`: The order was delivered. - `Canceled`: The order was canceled. This status is final.
  - Allowed values: `Placed`, `Paid`, `Initiated`, `Dispatched`, `Delivered`, `Canceled`
- `createdAt` (datetime, required) — When the order was placed, in UTC.
- `createdBy` (string, required) — Who placed the order.
- `updatedAt` (datetime, required) — When the order was last updated, in UTC.
- `updatedBy` (string, required) — Who last updated the order.
- `organizationId` (long, required) — The ID of the organization the order is for.
- `organizationName` (string, required) — The name of the organization the order is for.
- `paypointId` (long, required, nullable) — The ID of the paypoint the devices are for. `null` for an organization-level order.
- `paypointName` (string, required, nullable) — The name of the paypoint the devices are for. `null` for an organization-level order.
- `entryName` (string, required, nullable) — The entry name of the paypoint the devices are for. `null` for an organization-level order.
- `deviceSubtotal` (double, required) — The total price of the devices, before shipping.
- `shippingTotal` (double, required) — The total shipping cost.
- `total` (double, required) — The order total, including shipping.
- `currency` (string, required) — The currency of the order's amounts, for example `USD`.
- `billTo` (DeviceOrderAddressDetail, required) — The billing address for the order.
- `shipTo` (DeviceOrderAddressDetail, required) — The address the devices ship to.
- `contactName` (string, required, nullable) — The name of the contact person for the order.
- `contactEmail` (string, required) — The contact email for the order.
- `contactPhone` (string, required, nullable) — The contact phone number for the order.
- `payment` (DeviceOrderPayment, required) — The order's payment details.
- `shipment` (DeviceOrderShipment, required) — The order's shipping and tracking details.
- `lines` (list of DeviceOrderLineDetail, required) — The devices on the order.
- `history` (list of DeviceOrderHistoryEvent, required) — The order's events, oldest first.
- `allowedNextStates` (list of enum, required) — The statuses you can move the order to from its current status. Use it to decide what to show your users, instead of building the order lifecycle into your code.
  - Allowed values: `Placed`, `Paid`, `Initiated`, `Dispatched`, `Delivered`, `Canceled`
- `termsAcceptedAt` (datetime, required) — When the person placing the order accepted the terms, in UTC.

### PayabliErrorBodyResponseData

Object with detailed error context.

- `explanation` (string, optional) — Human-readable explanation of what happened.
- `todoAction` (string, optional) — Suggested resolution.

### DeviceOrderAddressDetail

A postal address on an order.

- `name` (string, required, nullable) — The recipient's name, when it's different from the contact name.
- `company` (string, required, nullable) — The company name printed on the invoice and shipping label.
- `line1` (string, required) — The street address.
- `line2` (string, required, nullable) — The suite, floor, or unit.
- `city` (string, required) — The city.
- `state` (string, required) — The state or province.
- `zip` (string, required) — The postal code.
- `country` (string, required) — The two-letter ISO 3166-1 alpha-2 country code.

### DeviceOrderPayment

The order's payment details.

- `paymentOption` (enum, required) — How the order is paid for. Defaults to `PayNow`. * `PayNow`: The buyer pays by card. After you place the order, collect the card with the embedded component and pay the order with `POST /DeviceOrder/{orderNumber}/pay`. Use `paymentOptions` in the catalog response to see which options are available.
  - Allowed values: `PayNow`
- `paymentStatus` (enum, required) — Where the order's payment stands. - `Pending`: The `PayNow` order isn't paid yet. - `Paid`: The order was charged. - `Voided`: The paid order was canceled before the payment settled. - `Refunded`: The paid order was canceled after the payment settled.
  - Allowed values: `Pending`, `Paid`, `Voided`, `Refunded`
- `invoiceId` (long, required) — The ID of the invoice Payabli created for the order.
- `invoiceNumber` (string, required) — The number of the invoice Payabli created for the order.
- `paidAt` (datetime, required, nullable) — When the order was paid, in UTC. `null` until it's paid.
- `method` (string, required, nullable) — The payment method used. `null` until the order is paid.
- `lastFour` (string, required, nullable) — The last four digits of the card used. `null` until the order is paid.
- `transactionId` (string, required, nullable) — The ID of the payment transaction. `null` until the order is paid.

### DeviceOrderShipment

The order's shipping and tracking details.

- `trackingCarrier` (string, required, nullable) — The shipping carrier. `null` until Payabli ships the order.
- `trackingNumber` (string, required, nullable) — The carrier's tracking number. `null` until Payabli ships the order.
- `expectedShipAt` (datetime, required, nullable) — When Payabli expects to ship the order, in UTC.
- `dispatchedAt` (datetime, required, nullable) — When Payabli shipped the order, in UTC.
- `deliveredAt` (datetime, required, nullable) — When the order was delivered, in UTC.
- `canceledAt` (datetime, required, nullable) — When the order was canceled, in UTC.
- `cancelReason` (string, required, nullable) — The reason sent when the order was canceled.
- `trackingUrl` (string, required, nullable) — A link to the carrier's tracking page. `null` until Payabli ships the order.
- `events` (list of DeviceOrderTrackingEvent, required) — The carrier's tracking scans. Empty before the carrier's first scan.

### DeviceOrderLineDetail

One device on an order.

- `id` (long, required) — The line's internal ID.
- `deviceProfileId` (long, required) — The ID of the device, from the device catalog.
- `profileCode` (string, required) — The device's code in the catalog.
- `name` (string, required) — The device's name.
- `make` (string, required) — The device's manufacturer.
- `model` (string, required) — The device's model.
- `quantity` (integer, required) — The number of units ordered.
- `unitPrice` (double, required) — The price of one unit.
- `unitShipping` (double, required) — The shipping cost for one unit.
- `shippingDays` (integer, required) — The estimated number of days to ship the device.
- `lineTotal` (double, required) — The line total, including shipping.
- `serials` (list of string, required) — The serial numbers of the units shipped for this line. Empty until Payabli ships the order.

### DeviceOrderHistoryEvent

One event in the order's history.

- `at` (datetime, required) — When the event happened, in UTC.
- `event` (string, required) — The event name, for example `DeviceOrderPlaced` or `DeviceOrderCanceled`.
- `fromStatus` (enum, required, nullable) — The status before the event. `null` for the event that placed the order.
  - Allowed values: `Placed`, `Paid`, `Initiated`, `Dispatched`, `Delivered`, `Canceled`
- `toStatus` (enum, required) — The status after the event.
  - Allowed values: `Placed`, `Paid`, `Initiated`, `Dispatched`, `Delivered`, `Canceled`
- `actingUser` (string, required) — Who caused the event.
- `note` (string, required, nullable) — A note about the event.

### DeviceOrderTrackingEvent

One carrier tracking scan.

- `eventDate` (datetime, required, nullable) — When the carrier recorded the scan, in UTC.
- `location` (string, required, nullable) — Where the scan happened, as the carrier reports it.
- `description` (string, required, nullable) — What happened, as the carrier reports it.

## Examples

**Request**

```json
{
  "reason": "Ordered the wrong device"
}
```

**Response**

```json
{
  "responseText": "Success",
  "responseData": {
    "id": 36,
    "orderNumber": "DO-000036",
    "status": "Canceled",
    "createdAt": "2026-10-16T15:28:48.972394+00:00",
    "createdBy": "900123",
    "updatedAt": "2026-10-16T15:31:21.8218313Z",
    "updatedBy": "900123",
    "organizationId": 900123,
    "organizationName": "Pilgrim Planner",
    "paypointId": 3040,
    "paypointName": "Sunshine Gutters",
    "entryName": "8cfec329267",
    "deviceSubtotal": 416,
    "shippingTotal": 18,
    "total": 434,
    "currency": "USD",
    "billTo": {
      "name": null,
      "company": null,
      "line1": "123 Main St",
      "line2": null,
      "city": "Austin",
      "state": "TX",
      "zip": "78701",
      "country": "US"
    },
    "shipTo": {
      "name": null,
      "company": null,
      "line1": "123 Main St",
      "line2": null,
      "city": "Austin",
      "state": "TX",
      "zip": "78701",
      "country": "US"
    },
    "contactName": "Jordan Smith",
    "contactEmail": "jordan.smith@example.com",
    "contactPhone": "5555550100",
    "payment": {
      "paymentOption": "PayNow",
      "paymentStatus": "Pending",
      "invoiceId": 3675,
      "invoiceNumber": "INV-2346",
      "paidAt": null,
      "method": null,
      "lastFour": null,
      "transactionId": null
    },
    "shipment": {
      "trackingCarrier": null,
      "trackingNumber": null,
      "expectedShipAt": null,
      "dispatchedAt": null,
      "deliveredAt": null,
      "canceledAt": "2026-10-16T15:31:21.8218313Z",
      "cancelReason": "Ordered the wrong device",
      "trackingUrl": null,
      "events": []
    },
    "lines": [
      {
        "id": 36,
        "deviceProfileId": 67,
        "profileCode": "ingenico-ingenico-dx6000",
        "name": "Ingenico DX6000",
        "make": "Ingenico",
        "model": "DX6000",
        "quantity": 1,
        "unitPrice": 416,
        "unitShipping": 18,
        "shippingDays": 3,
        "lineTotal": 434,
        "serials": []
      }
    ],
    "history": [
      {
        "at": "2026-10-16T15:28:49.071752+00:00",
        "event": "DeviceOrderPlaced",
        "fromStatus": null,
        "toStatus": "Placed",
        "actingUser": "900123",
        "note": null
      },
      {
        "at": "2026-10-16T15:31:21.847394+00:00",
        "event": "DeviceOrderCanceled",
        "fromStatus": "Placed",
        "toStatus": "Canceled",
        "actingUser": "900123",
        "note": "Ordered the wrong device"
      }
    ],
    "allowedNextStates": [],
    "termsAcceptedAt": "2026-10-16T15:28:48.972394+00:00"
  },
  "responseCode": 1,
  "pageIdentifier": null,
  "roomId": 0,
  "isSuccess": true
}
```

**SDK Code**

```python
import requests

url = "https://api-sandbox.payabli.com/api/DeviceOrder/DO-000036/cancel"

payload = { "reason": "Ordered the wrong device" }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api-sandbox.payabli.com/api/DeviceOrder/DO-000036/cancel';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"reason":"Ordered the wrong device"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api-sandbox.payabli.com/api/DeviceOrder/DO-000036/cancel"

	payload := strings.NewReader("{\n  \"reason\": \"Ordered the wrong device\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api-sandbox.payabli.com/api/DeviceOrder/DO-000036/cancel")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"reason\": \"Ordered the wrong device\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-sandbox.payabli.com/api/DeviceOrder/DO-000036/cancel")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"reason\": \"Ordered the wrong device\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-sandbox.payabli.com/api/DeviceOrder/DO-000036/cancel', [
  'body' => '{
  "reason": "Ordered the wrong device"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api-sandbox.payabli.com/api/DeviceOrder/DO-000036/cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"reason\": \"Ordered the wrong device\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["reason": "Ordered the wrong device"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api-sandbox.payabli.com/api/DeviceOrder/DO-000036/cancel")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```