# Cancel a post

Cancels a scheduled post so it never goes out. DELETE /posts/{postId}.

`DELETE https://api.tiktornado.com/api/v1/posts/{postId}`

Scope: `posts:write`. Needs an `Idempotency-Key` header.

Cancels a scheduled post so it never goes out. Only a post waiting for its time can be cancelled (`invalid_state` otherwise). Refused from 10 minutes before the post goes out (`post_locked`), so always for a post sent with `postNow`. The answer's status is `cancelling` until TikTok's scheduler has dropped the post.

## Path parameters

- `postId` string, required: The post, from `POST /posts` or `GET /posts`. Matches `^[A-Za-z0-9]{1,64}$`.

## Header parameters

- `Idempotency-Key` string, required: A unique string you make up for this change, for example a UUID: 1 to 255 visible ASCII characters, no spaces. Send the same key with the same body to retry safely. Missing or malformed: 400 `idempotency_key_required`, before anything runs. Matches `^[\x21-\x7e]{1,255}$`.

## Examples

```bash
curl -X DELETE 'https://api.tiktornado.com/api/v1/posts/k174wq9nrm6t2f0bd3xh8pz5a87v1c2e' \
  -H "Authorization: Bearer $TIKTORNADO_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

```js
const response = await fetch("https://api.tiktornado.com/api/v1/posts/k174wq9nrm6t2f0bd3xh8pz5a87v1c2e", {
  method: "DELETE",
  headers: {
    Authorization: `Bearer ${process.env.TIKTORNADO_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
});
const data = await response.json();
```

```python
import os
import uuid

import requests

response = requests.delete(
    "https://api.tiktornado.com/api/v1/posts/k174wq9nrm6t2f0bd3xh8pz5a87v1c2e",
    headers={
        "Authorization": f"Bearer {os.environ['TIKTORNADO_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
)
data = response.json()
```

## Response 200

The post is being cancelled.

- `Idempotent-Replayed`: `true` when this is the stored answer to an earlier request with the same `Idempotency-Key`. Absent otherwise.

- `id` string, required: An id, letters and digits only. Matches `^[A-Za-z0-9]{1,64}$`.
- `status` string, required: Always `cancelling`.

```json
{
  "id": "k174wq9nrm6t2f0bd3xh8pz5a87v1c2e",
  "status": "cancelling"
}
```

## Errors

| Status | Reason | Message |
| --- | --- | --- |
| 400 | `idempotency_key_required` | Send an Idempotency-Key header with every change, so a retry can't make it twice. |
| 400 | `post_locked` | This post goes out in 10 minutes or less, so it can't be changed now. |
| 400 | `post_already_published` | This post is already live, so it can't be changed. |
| 400 | `invalid_state` | This can't be done right now. Refresh and try again. |
| 401 | `api_key_invalid` | This API key isn't valid. Check it, or create a new one in the app. |
| 403 | `access_locked` | Your subscription isn't active, so this can't be changed right now. Visit Billing to fix it. |
| 403 | `api_scope_missing` | This API key can't do this. Create a key with the access it needs in the app. |
| 404 | `not_found` | We couldn't find this. |
| 409 | `idempotency_in_progress` | A request with this Idempotency-Key is still running. Try again in a moment. |
| 422 | `idempotency_key_reused` | This Idempotency-Key was already used for a different request. Use a new one. |
| 429 | `slow_down` | You're going a bit fast. Wait a moment and try again. |
| 500 | `unknown_error` | Something went wrong on our side. We're on it. |
| 503 | `service_unavailable` | Something went wrong on our side. We're on it. |