# Cancel an invoice

## Overview

You can cancel an invoice so the customer can no longer pay it. This is useful when the invoice contains a mistake. Cancellation requires two conditions:

* Invoice status: Unpaid
* Payment page views: 0

If the invoice belongs to another project and the key is restricted to a project, the method responds with `Restricted project`. If you have no invoice with that identifier—`Invoice not found`. If the invoice is found but the cancellation conditions are not met—`Invoice cannot be canceled`.

## Request

```bash
curl -X POST https://api.bitsby.app/invoices/cancel \
  -H "Authorization: Token MSvL2ltaDZdWVjmZURURMVWhqSJLT2NURjhL2Fla1Z1T1IxQTltKs1T3Ay" \
	-F "invoiceId=ade9550d-3dc7-4fd3-b94e-3b4c12aaaa0c"
```

## Request parameters

| Parameter   | Data type | Description               | Example                              | Required? |
| ----------- | --------- | ------------------------- | ------------------------------------ | --------- |
| `invoiceId` | UUID      | Invoice ID in UUID format | ade9550d-3dc7-4fd3-b94e-3b4c12aaaa0c | yes       |

## Response example

```json
{
   "result":"success",
   "data":"Invoice canceled"
}
```
