> ## Documentation Index
> Fetch the complete documentation index at: https://docs.swiftpay.cx/llms.txt
> Use this file to discover all available pages before exploring further.

# Cancel Withdrawal

> Cancel a pending withdrawal request

# Cancel Withdrawal

Cancels a pending withdrawal request. Only withdrawals with status `pending` can be cancelled.

<Warning>Withdrawals in `processing` status cannot be cancelled.</Warning>

## Request

<ParamField header="Authorization" type="string" required>
  Bearer token with your API key
</ParamField>

<ParamField path="id" type="string" required>
  The unique identifier of the withdrawal to cancel
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  Whether the request was successful
</ResponseField>

<ResponseField name="data" type="object">
  <Expandable title="properties">
    <ResponseField name="id" type="string">
      Withdrawal identifier
    </ResponseField>

    <ResponseField name="status" type="string">
      Updated status (`cancelled`)
    </ResponseField>

    <ResponseField name="amountInCents" type="integer">
      Amount returned to available balance
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.swiftpay.cx/api/withdrawals/wd_abc123/cancel \
    -H "Authorization: Bearer mp_live_your_api_key"
  ```

  ```javascript JavaScript theme={null}
  const withdrawalId = "wd_abc123";

  const response = await fetch(
     `https://api.swiftpay.cx/api/withdrawals/${withdrawalId}/cancel`,
     {
        method: "POST",
        headers: {
           Authorization: "Bearer mp_live_your_api_key",
        },
     }
  );

  const result = await response.json();

  if (result.success) {
     console.log("Withdrawal cancelled, funds returned to balance");
  }
  ```

  ```python Python theme={null}
  import requests

  withdrawal_id = 'wd_abc123'

  response = requests.post(
      f'https://api.swiftpay.cx/api/withdrawals/{withdrawal_id}/cancel',
      headers={'Authorization': 'Bearer mp_live_your_api_key'}
  )

  result = response.json()
  if result['success']:
      print('Withdrawal cancelled')
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "success": true,
    "data": {
      "id": "wd_abc123",
      "status": "cancelled",
      "amountInCents": 50000
    }
  }
  ```

  ```json 400 theme={null}
  {
     "success": false,
     "error": {
        "type": "validation_error",
        "message": "Cannot cancel withdrawal in processing status",
        "requestId": "req_abc123"
     }
  }
  ```

  ```json 404 theme={null}
  {
     "success": false,
     "error": {
        "type": "not_found",
        "message": "Withdrawal not found",
        "requestId": "req_abc123"
     }
  }
  ```
</ResponseExample>

## Cancellation Rules

| Current Status | Can Cancel? |
| -------------- | ----------- |
| `pending`      | ✅ Yes       |
| `processing`   | ❌ No        |
| `completed`    | ❌ No        |
| `failed`       | ❌ No        |
| `cancelled`    | ❌ No        |

<Note>
  When a withdrawal is cancelled, the funds are immediately returned to your
  available balance.
</Note>
