> This page is for Developer.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.feedonomics.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.feedonomics.com/_mcp/server.

# Create a cancellation on an order

POST https://api.feedamp.feedonomics.com/api/v2/orders/{order-id}/cancellations
Content-Type: application/json

Post a cancellation of line item

Reference: https://docs.feedonomics.com/developer/api-reference/rest/feed-amp-order-api-v2/cancellations/post-get-cancellations

## Authentication

- `token` header (required) — The Authentication token obtained from the get_token route.
- `x-api-key` header (required) — The SSO token obtained from the Feedonomics platform SSO token route.

## Request

### Path parameters

- `order-id` (string, required) — FeedAMP Order ID

### Headers

- `client` (integer, required) — The ID of the client making the request

### Body (application/json)

This endpoint expects a Cancellation.

- `cancellation_lines` (list of LineQuantity, required)
- `reason` (enum, required) — Reason provided for the order line's cancellation
  - Allowed values: `customer_cancelled`, `customer_rejected`, `unable_to_ship`, `out_of_stock`, `price_error`, `tax_error`, `shipping_price_error`, `fraud`, `other`

## Response

### 201

Cancellation object

- `id` (string, required) — Unique identifier for a record
- `cancellation_lines` (list of LineQuantity, required)
- `reason` (enum, required) — Reason provided for the order line's cancellation
  - Allowed values: `customer_cancelled`, `customer_rejected`, `unable_to_ship`, `out_of_stock`, `price_error`, `tax_error`, `shipping_price_error`, `fraud`, `other`

## Errors

### 400 Bad Request Error

Validation error detected when creating/updating a record

- `error` (string, required)

### 401 Unauthorized Error

Error validating credentials or access to resources.

- `error` (string, required)

### 404 Not Found Error

Requested order does not exist

- `any`

### 500 Internal Server Error

An unexpected server error occurred. Please contact Feedonomics Support if error persists.

- `error` (string, required)

### 503 Service Unavailable Error

Server is temporarily unable to handle the request

- `error` (string, required)

## Types

### LineQuantity

Specification of an order line number and quantity for that line

- `line_id` (string, required) — Unique identifier for a record
- `quantity` (integer, required)

## Examples

**Request**

```json
{
  "cancellation_lines": [
    {
      "line_id": "109872189273617283",
      "quantity": 1
    }
  ],
  "reason": "customer_cancelled"
}
```

**Response**

```json
{
  "id": "109872189273617283",
  "cancellation_lines": [
    {
      "line_id": "109872189273617283",
      "quantity": 1
    }
  ],
  "reason": "customer_cancelled"
}
```

**SDK Code**

```python
import requests

url = "https://api.feedamp.feedonomics.com/api/v2/orders/109872189273617283/cancellations"

payload = {
    "cancellation_lines": [
        {
            "line_id": "109872189273617283",
            "quantity": 1
        }
    ],
    "reason": "customer_cancelled"
}
headers = {
    "client": "1",
    "token": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.feedamp.feedonomics.com/api/v2/orders/109872189273617283/cancellations';
const options = {
  method: 'POST',
  headers: {client: '1', token: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"cancellation_lines":[{"line_id":"109872189273617283","quantity":1}],"reason":"customer_cancelled"}'
};

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.feedamp.feedonomics.com/api/v2/orders/109872189273617283/cancellations"

	payload := strings.NewReader("{\n  \"cancellation_lines\": [\n    {\n      \"line_id\": \"109872189273617283\",\n      \"quantity\": 1\n    }\n  ],\n  \"reason\": \"customer_cancelled\"\n}")

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

	req.Header.Add("client", "1")
	req.Header.Add("token", "<apiKey>")
	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.feedamp.feedonomics.com/api/v2/orders/109872189273617283/cancellations")

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

request = Net::HTTP::Post.new(url)
request["client"] = '1'
request["token"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"cancellation_lines\": [\n    {\n      \"line_id\": \"109872189273617283\",\n      \"quantity\": 1\n    }\n  ],\n  \"reason\": \"customer_cancelled\"\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.feedamp.feedonomics.com/api/v2/orders/109872189273617283/cancellations")
  .header("client", "1")
  .header("token", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"cancellation_lines\": [\n    {\n      \"line_id\": \"109872189273617283\",\n      \"quantity\": 1\n    }\n  ],\n  \"reason\": \"customer_cancelled\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.feedamp.feedonomics.com/api/v2/orders/109872189273617283/cancellations', [
  'body' => '{
  "cancellation_lines": [
    {
      "line_id": "109872189273617283",
      "quantity": 1
    }
  ],
  "reason": "customer_cancelled"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'client' => '1',
    'token' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.feedamp.feedonomics.com/api/v2/orders/109872189273617283/cancellations");
var request = new RestRequest(Method.POST);
request.AddHeader("client", "1");
request.AddHeader("token", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"cancellation_lines\": [\n    {\n      \"line_id\": \"109872189273617283\",\n      \"quantity\": 1\n    }\n  ],\n  \"reason\": \"customer_cancelled\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "client": "1",
  "token": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "cancellation_lines": [
    [
      "line_id": "109872189273617283",
      "quantity": 1
    ]
  ],
  "reason": "customer_cancelled"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.feedamp.feedonomics.com/api/v2/orders/109872189273617283/cancellations")! 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()
```