> For the complete documentation index, see [llms.txt](https://fez-delivery-co.gitbook.io/fezcorporate-api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fez-delivery-co.gitbook.io/fezcorporate-api-docs/api-endpoints/orders/cancel.md).

# Cancel

{% hint style="info" %}
An order can only be cancelled while its `orderStatus` is one of:

* `Pending Pick-Up`
* `Pending Payment`
* `Pending Drop-off`
* `Dropped-off`
* `Rejected At Drop-off`
* `Failed Pick-Up`

Any other status (e.g. `Delivered`, `Dispatched`) is rejected.<br>

* Only single-order cancellation is supported (no bulk cancel).
* Only business/organisation wallets are supported, individual wallets are out of scope for this endpoint.
  {% endhint %}

Cancel Order

## Endpoint => /order/cancel

<mark style="color:$success;">`POST`</mark> `/order/cancel`

#### Headers

| Name                                             | Type   | Description       |
| ------------------------------------------------ | ------ | ----------------- |
| Authorization <mark style="color:red;">\*</mark> | String | Your Bearer Token |
| secret-key<mark style="color:red;">\*</mark>     | String | Your Secret Key   |

#### Request Body

| Name                                          | Type   | Description                                                                    |
| --------------------------------------------- | ------ | ------------------------------------------------------------------------------ |
| orderNo<mark style="color:$danger;">\*</mark> | String | The order to cancel. Must belong to the requesting organisation.               |
| reason<mark style="color:$danger;">\*</mark>  | String | Cancellation reason, max 255 characters. Stored on the order as Cancel Reason. |

{% tabs %}
{% tab title="200 Success" %}

```json
{ 
    "status": "Success", 
    "description": "Order Successfully Cancelled" 
}
```

{% endtab %}

{% tab title="400 Bad Request" %}

```json
{ 
    "status": "Error", 
    "description": "Invalid order status: Only orders in Pending Pick-Up, Pending Payment, Pending Drop-off, Dropped-off, Rejected At Drop-off, Failed Pick-Up can be cancelled" 
}
```

{% endtab %}

{% tab title="401 Unauthorized" %}

```json
{
    "status": "Error",
    "description": "Organization Secret Key is Required"
}
```

{% endtab %}

{% tab title="442 Unprocessed Entities" %}

```json
{ 
  "status": "Error",
  "description": "Order not found or does not belong to your organization." 
 }
```

{% endtab %}
{% endtabs %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://apisandbox.fezdelivery.co/v1/order/cancel',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
  "orderNo": "9MCW24062553",
  "reason": "Customer requested cancellation"
}',
  CURLOPT_HTTPHEADER => array(
    'secret-key: {{Your Secret Key}}'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```
