# Cancel an email

> POST /emails/:id/cancel — cancel a scheduled email.

`POST /emails/:id/cancel`

Cancel a still-`scheduled` email so it is never sent. The email moves to the `canceled` status and its pending delivery job is removed. Only emails in the `scheduled` state can be canceled. See [Schedule email](https://www.sendping.co/docs/emails/schedule).

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | The id of the scheduled email to cancel. |

## Request

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.emails.cancel('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794');
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Emails.cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->emails->cancel('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794');
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Emails.cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

canceled, err := client.Emails.Cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
```

**Rust**

```rust
use sendping::SendPing;

let mb = SendPing::new("mb_xxxxxxxxx");

let _canceled = mb.emails.cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794").await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendPingResponse response = sendping.emails().cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794");
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.EmailCancelAsync("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794");
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/emails/49a3999c-0ce1-4ea6-ab68-afcd6dc2e794/cancel' \
  -H 'Authorization: Bearer mb_xxxxxxxxx'
```

**CLI**

```bash
sendping emails cancel 49a3999c-0ce1-4ea6-ab68-afcd6dc2e794
```

## Response

```json
{
  "object": "email",
  "id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
}
```

## Errors

Returns `not_found` (404) if the email does not exist for your account; `validation_error` if the email is not in the `scheduled` state (i.e. it has already been sent or canceled). See the [error reference](https://www.sendping.co/docs/api/errors).
