# Autopilot

Let Posttar create and publish on a weekly schedule.

Autopilot creates and publishes on its own, on a weekly grid of slots. Each slot is a weekday (`dayOfWeek`, 0 for Monday), a whole hour in the project's timezone (`hour`), and an optional `theme` for what to write about. Without a theme, autopilot picks the topic.

Read the current grid:

```bash
curl -H "Authorization: Bearer $POSTTAR_KEY" "https://api.posttar.com/v1/projects/c85848ba-.../autopilot"
```

```json
{
  "projectId": "c85848ba-...",
  "enabled": false,
  "emailReport": true,
  "requiresApproval": false,
  "timezone": "America/Sao_Paulo",
  "slots": [],
  "blockers": ["no_slots", "no_instagram"]
}
```

`blockers` is the useful field: it lists what is stopping autopilot from running. `no_slots` means the grid is empty, `no_instagram` means the project has no connected account, `no_subscription` means the plan lapsed. Turning it on while a blocker stands will not make it publish.

## Set up a weekly schedule

Add slots, then turn it on.

### 1. Add a slot: Tuesday at 09:00. `dayOfWeek` counts from Monday as 0.

```bash
curl -X POST -H "Authorization: Bearer $POSTTAR_KEY" -H "Content-Type: application/json" \
  -d '{"dayOfWeek":1,"hour":9,"theme":"a practical tip, no jargon"}' \
  "https://api.posttar.com/v1/projects/c85848ba-.../autopilot/slots"
```

### 2. Turn autopilot on.

```bash
curl -X POST -H "Authorization: Bearer $POSTTAR_KEY" \
  "https://api.posttar.com/v1/projects/c85848ba-.../autopilot/enable"
```

### 3. Check that no impediment is left.

```bash
curl -H "Authorization: Bearer $POSTTAR_KEY" "https://api.posttar.com/v1/projects/c85848ba-.../autopilot"
```

> With `requiresApproval` on, autopilot creates the post and stops at `draft` instead of publishing. Use it when you want a human to look before anything goes out.
