# Cancel a scheduled email

> Stop a scheduled email before its send time. Nothing is sent or charged.

`POST https://api-connect.nxiom.com/api/v1/emails/messages/{messageId}/cancel`

## Authorization

Requires `email.send`. A key restricted to one sending domain can cancel only emails sent from that domain.

## Path parameters

| Field | Type | Description |
| --- | --- | --- |
| `messageId` | string · required | The `messageId` returned when you scheduled the send. |

## Request

### cURL

```shell
curl -X POST "https://api-connect.nxiom.com/api/v1/emails/messages/YOUR_MESSAGE_ID/cancel" \
  -H "Authorization: Bearer $NEXIOM_API_KEY"
```

### Node.js

```typescript
import { NexiomConnect } from '@nexiom/connect';

const apiKey = process.env.NEXIOM_API_KEY;
if (!apiKey) throw new Error('Set NEXIOM_API_KEY');

const nexiom = new NexiomConnect({ apiKey });

const { data, error } = await nexiom.emails.cancel('YOUR_MESSAGE_ID');

if (error) throw new Error(`${error.code}: ${error.message}`);
console.log(data.status, data.canceledAt);
```

### PHP

```php
<?php

use Nexiom\Connect\NexiomConnect;

$apiKey = getenv('NEXIOM_API_KEY');
if (!$apiKey) {
    throw new RuntimeException('Set NEXIOM_API_KEY');
}

$nexiom = new NexiomConnect($apiKey);

$result = $nexiom->emails->cancel('YOUR_MESSAGE_ID');

echo $result['status'], ' ', $result['canceledAt'];
```

## Response

HTTP `200`. Every scheduled delivery of the message becomes `canceled`, and [email.canceled](/docs/webhooks/emails/canceled) fires for each one.

Cancelling an email that is already canceled returns the same result, so retrying is safe. Recipients that were suppressed when you scheduled the send keep the `suppressed` status.

### 200 OK

Scheduled email canceled.

```json
{
  "message": "Scheduled email canceled",
  "data": {
    "messageId": "message_example",
    "status": "canceled",
    "canceledAt": "2026-10-04T12:00:00.000Z",
    "deliveryIds": [
      "delivery_example"
    ]
  }
}
```

### 401 Unauthorized

The API key is missing, malformed, revoked, or expired.

```json
{
  "error": "unauthorized",
  "message": "Invalid API key",
  "correlationId": "req_example"
}
```

### 403 Forbidden

The API key lacks a required permission, or its domain restriction does not allow this sender.

```json
{
  "error": "not_allowed",
  "message": "Missing required API key permissions: email.full_access",
  "correlationId": "req_example"
}
```

### 404 Not Found

No resource with this ID exists in the API key’s project.

```json
{
  "error": "not_found",
  "code": "resource_not_found",
  "message": "Resource not found",
  "correlationId": "req_example"
}
```

### 409 Conflict

The email is no longer scheduled: it was sent immediately, or its send time has already arrived.

```json
{
  "error": "conflict",
  "message": "Only a scheduled email can be canceled",
  "correlationId": "req_example"
}
```

---

Source: https://connect.nxiom.com/docs/api/emails/cancel
