## Cancel order

### cURL

```bash
curl --request POST \
  --url https://prod01.oms.fabric.inc/api/v2/order/cancel \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-site-context: <x-site-context>' \
  --data @- <<EOF
{
  "orderId": "62f3982438bcab1951be0a19",
  "reasonCode": "wrong item",
  "subReasonCode": "Ordered item doesn't match",
  "source": "<string>",
  "employeeId": "AD5069",
  "note": "Wrong item is sent to customer",
  "policyCode": "Cancel",
  "attributes": {
    "IsCancellationEligibile": true
  },
  "items": [
    {
      "lineItemId": 12345,
      "quantity": 1,
      "reasonCode": "wrong item",
      "subReasonCode": "Mismatched item"
    }
  ]
}
EOF
```

### Python

```python
import requests

url = "https://prod01.oms.fabric.inc/api/v2/order/cancel"

payload = {
    "orderId": "62f3982438bcab1951be0a19",
    "reasonCode": "wrong item",
    "subReasonCode": "Ordered item doesn't match",
    "source": "<string>",
    "employeeId": "AD5069",
    "note": "Wrong item is sent to customer",
    "policyCode": "Cancel",
    "attributes": { "IsCancellationEligibile": True },
    "items": [
        {
            "lineItemId": 12345,
            "quantity": 1,
            "reasonCode": "wrong item",
            "subReasonCode": "Mismatched item"
        }
    ]
}
headers = {
    "x-site-context": "<x-site-context>",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.text)
```

### JavaScript (Fetch)

```javascript
const options = {
  method: 'POST',
  headers: {
    'x-site-context': '<x-site-context>',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    orderId: '62f3982438bcab1951be0a19',
    reasonCode: 'wrong item',
    subReasonCode: 'Ordered item doesn\'t match',
    source: '<string>',
    employeeId: 'AD5069',
    note: 'Wrong item is sent to customer',
    policyCode: 'Cancel',
    attributes: {IsCancellationEligibile: true},
    items: [
      {
        lineItemId: 12345,
        quantity: 1,
        reasonCode: 'wrong item',
        subReasonCode: 'Mismatched item'
      }
    ]
  })
};

fetch('https://prod01.oms.fabric.inc/api/v2/order/cancel', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### PHP

```php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://prod01.oms.fabric.inc/api/v2/order/cancel",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'orderId' => '62f3982438bcab1951be0a19',
    'reasonCode' => 'wrong item',
    'subReasonCode' => 'Ordered item doesn\'t match',
    'source' => '<string>',
    'employeeId' => 'AD5069',
    'note' => 'Wrong item is sent to customer',
    'policyCode' => 'Cancel',
    'attributes' => [
        'IsCancellationEligibile' => true
    ],
    'items' => [
        [
                'lineItemId' => 12345,
                'quantity' => 1,
                'reasonCode' => 'wrong item',
                'subReasonCode' => 'Mismatched item'
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json",
    "x-site-context: <x-site-context>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

### Go

```go
package main

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

func main() {

url := "https://prod01.oms.fabric.inc/api/v2/order/cancel"

payload := strings.NewReader("{\n  \"orderId\": \"62f3982438bcab1951be0a19\",\n  \"reasonCode\": \"wrong item\",\n  \"subReasonCode\": \"Ordered item doesn't match\",\n  \"source\": \"<string>\",\n  \"employeeId\": \"AD5069\",\n  \"note\": \"Wrong item is sent to customer\",\n  \"policyCode\": \"Cancel\",\n  \"attributes\": {\n    \"IsCancellationEligibile\": true\n  },\n  \"items\": [\n    {\n      \"lineItemId\": 12345,\n      \"quantity\": 1,\n      \"reasonCode\": \"wrong item\",\n      \"subReasonCode\": \"Mismatched item\"\n    }\n  ]\n}")

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

req.Header.Add("x-site-context", "<x-site-context>")
	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(string(body))
}
```

### Response

#### Status Codes

- **200**: Order cancelled
- **400**: Bad request
- **404**: Order not found
- **500**: Internal server error

#### Example Response

```json
{
  "orderNumber": "309019176",
  "channelId": "12",
  "statusCode": "ORDER_CREATED",
  "items": [
    {
      "lineItemId": "b03b72dc-78d8-4ea4-90fc-2fe6a1fe6569",
      "lineItemNumber": 1,
      "itemId": "1234",
      "sku": "P1234",
      "shipToId": "b03b72dc-78d8-4ea4-90fc-2fe6a1fe6569",
      "channelId": "WHBM",
      "segment": "P1234",
      "vendorId": "P1234",
      "title": "Item",
      "type": "WEB_SHIP",
      "subType": "Borderfree",
      "backorder": true,
      "orderedQuantity": 60,
      "backOrderedQuantity": 10,
      "pendingShippedQuantity": 10,
      "pendingShippedBackOrderQuantity": 10,
      "shippedQuantity": 10,
      "deliveredQuantity": 10,
      "invoiceQuantity": 10,
      "cancelledQuantity": 10,
      "pendingReturnQuantity": 10,
      "processingReturnQuantity": 10,
      "rejectedReturnQuantity": 10,
      "returnedQuantity": 10,
      "reshippedQuantity": 10,
      "uom": "EA",
      "itemUnitPrice": 10,
      "itemSubTotal": 600,
      "originalItemSubTotal": 600,
      "itemFeeTotal": 5,
      "originalFeeTotal": 5,
      "itemShippingTotal": 5,
      "originalShippingTotal": 5,
      "appeasementTotal": 5.5,
      "itemDiscountsTotal": 55,
      "originalDiscounts": 55,
      "itemTaxTotal": 5,
      "originalTaxTotal": 555,
      "itemTotal": 555,
      "originalItemTotal": 555,
      "outstandingItemTotal": 555,
      "originalOutstandingItemTotal": 555,
      "invoiceTotal": 555,
      "currency": "USD",
      "employeeId": "5345HJH",
      "associateId": "5345HJH"
    }
  ],
  "version": 123,
  "orderId": "5349b4ddd2781d08c09890f4",
  "orderDate": "2022-05-12T09:30:31.198Z",
  "cancellationDate": "2022-05-12T09:30:31.198Z",
  "allocationDate": "2022-05-12T09:30:31.198Z",
  "cartId": "b03b72dc-78d8-4ea4-90fc-2fe6a1fe6569",
  "type": "WEB",
  "subType": "International",
  "processName": "CANCEL",
  "employeeId": "43278",
  "orderSubTotal": 123.45,
  "originalSubTotal": 113.45,
  "orderDiscount": 1.23,
  "originalDiscounts": 1.45,
  "feeTotal": 12.34,
  "originalFeeTotal": 12.34,
  "taxTotal": 12.34,
  "appeasementTotal": 12.34,
  "originalTaxTotal": 12.34,
  "returnTotal": 12.34,
  "cancelTotal": 12.34,
  "invoiceTotal": 12.34,
  "orderTotal": 146.9,
  "originalOrderTotal": 146.9,
  "currency": "USD",
  "statusDescription": "Order Created"
}
```

#### Authorizations

**Authorization**: Bearer authentication header of the form `Bearer <token>`, where `<token>` is your auth token.

#### Headers Used

**x-site-context**: Required - A JSON object containing information about the source to pull from.
