# API: Messages

| Method | Path | What it does | Scope |
|---|---|---|---|
| GET | `/v1/church/messages` | Messages, newest first, and what the church has turned on | `messages:read` |
| POST | `/v1/church/messages` | Write a message, or a welcome step with after_days. Nothing is sent | `messages:write` |
| GET | `/v1/church/messages/:id` | One message as it will arrive, and how many people it reaches | `messages:read` |
| PATCH | `/v1/church/messages/:id` | Change a message that hasn't gone, turn a welcome step on or off, or remove a message from the list | `messages:write` |
| POST | `/v1/church/messages/:id/send` | Send a message to the number of people its preview showed, or send the rest of one that was stopped (web app only) | `messages:write` |
| POST | `/v1/church/messages/:id/stop` | Stop a message that's going out. Whoever hasn't got it yet doesn't | `messages:write` |
| POST | `/v1/church/messages/:id/test` | Email yourself a copy, as it will arrive (web app only) | `messages:write` |
| GET | `/v1/church/messages/consent/:id` | Has this person said yes to texts? | `messages:read` |
| PUT | `/v1/church/messages/consent/:id` | Record that someone said yes or no to texts, and how they said it (web app only) | `messages:write` |
| PATCH | `/v1/church/messages/settings` | Turn emails or texts to people on or off, and set the address emails show (web app only) | `messages:write` |

## Examples

### GET /v1/church/messages

Messages, newest first, and what the church has turned on

```bash
curl -s "https://api.chapelwren.com/v1/church/messages" \
  -H "Authorization: Bearer $CG_API_KEY"
```

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/messages`, {
  method: "GET",
  headers: { authorization: `Bearer ${process.env.CG_API_KEY}` },
});
const data = await res.json();
```

### POST /v1/church/messages

Write a message, or a welcome step with after_days. Nothing is sent

```bash
curl -s -X POST "https://api.chapelwren.com/v1/church/messages" \
  -H "Authorization: Bearer $CG_API_KEY" \
  -H "content-type: application/json" \
  -d '{}'
```

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/messages`, {
  method: "POST",
  headers: { authorization: `Bearer ${process.env.CG_API_KEY}`, "content-type": "application/json" },
  body: JSON.stringify({}), // fields: see the OpenAPI schema
});
const data = await res.json();
```

### GET /v1/church/messages/$ID

One message as it will arrive, and how many people it reaches

```bash
curl -s "https://api.chapelwren.com/v1/church/messages/$ID" \
  -H "Authorization: Bearer $CG_API_KEY"
```

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/messages/${id}`, {
  method: "GET",
  headers: { authorization: `Bearer ${process.env.CG_API_KEY}` },
});
const data = await res.json();
```

### PATCH /v1/church/messages/$ID

Change a message that hasn't gone, turn a welcome step on or off, or remove a message from the list

```bash
curl -s -X PATCH "https://api.chapelwren.com/v1/church/messages/$ID" \
  -H "Authorization: Bearer $CG_API_KEY" \
  -H "content-type: application/json" \
  -d '{}'
```

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/messages/${id}`, {
  method: "PATCH",
  headers: { authorization: `Bearer ${process.env.CG_API_KEY}`, "content-type": "application/json" },
  body: JSON.stringify({}), // fields: see the OpenAPI schema
});
const data = await res.json();
```

### POST /v1/church/messages/$ID/stop

Stop a message that's going out. Whoever hasn't got it yet doesn't

```bash
curl -s -X POST "https://api.chapelwren.com/v1/church/messages/$ID/stop" \
  -H "Authorization: Bearer $CG_API_KEY" \
  -H "content-type: application/json" \
  -d '{}'
```

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/messages/${id}/stop`, {
  method: "POST",
  headers: { authorization: `Bearer ${process.env.CG_API_KEY}`, "content-type": "application/json" },
  body: JSON.stringify({}), // fields: see the OpenAPI schema
});
const data = await res.json();
```

### GET /v1/church/messages/consent/$ID

Has this person said yes to texts?

```bash
curl -s "https://api.chapelwren.com/v1/church/messages/consent/$ID" \
  -H "Authorization: Bearer $CG_API_KEY"
```

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/messages/consent/${id}`, {
  method: "GET",
  headers: { authorization: `Bearer ${process.env.CG_API_KEY}` },
});
const data = await res.json();
```

Request and response schemas: [https://www.chapelwren.com/openapi.json](https://www.chapelwren.com/openapi.json). All resources: [API reference](https://www.chapelwren.com/docs/api).
