# API: Groups

| Method | Path | What it does | Scope |
|---|---|---|---|
| GET | `/v1/church/groups` | Groups, with how many are in each, who asked to join and when they last met | `groups:read` |
| POST | `/v1/church/groups` | Add a group | `groups:write` |
| GET | `/v1/church/groups/:id` | A group: its members, who asked to join and its last meetings | `groups:read` |
| PATCH | `/v1/church/groups/:id` | Change a group, close it, or open it again | `groups:write` |
| DELETE | `/v1/church/groups/:id/meetings/:day` | Remove a day's attendance | `groups:write` |
| PUT | `/v1/church/groups/:id/meetings/:day` | Who came to a group on a day. Sending it again corrects it | `groups:write` |
| POST | `/v1/church/groups/:id/members` | Put someone in a group, or make a member its leader. `over` goes past the size limit | `groups:write` |
| DELETE | `/v1/church/groups/:id/members/:person` | Take someone out of a group. Past attendance stays | `groups:write` |
| GET | `/v1/church/groups/:id/messages` | Whether people in a group can write to each other, and messages someone reported (web app only) | `groups:read` |
| PUT | `/v1/church/groups/:id/messages` | Let people in a group write to each other, or stop it (web app only) | `groups:write` |
| PUT | `/v1/church/groups/:id/messages/:message` | Hide a reported message, or keep it (web app only) | `groups:write` |
| POST | `/v1/church/groups/:id/requests/:request` | Say yes or no to someone who asked to join. Yes finds their record or adds them as a visitor | `groups:write` |
| PUT | `/v1/church/groups/:id/stopped/:person` | Stop someone writing in a group, or let them back (web app only) | `groups:write` |
| GET | `/v1/church/groups/prayers` | Prayer requests you may see, newest first. Requests for pastors only show to pastors, signed in (web app only) | `groups:read` |
| POST | `/v1/church/groups/prayers` | Write down a prayer request, and who may see it (web app only) | `groups:write` |
| PATCH | `/v1/church/groups/prayers/:id` | Correct a prayer request, mark it answered, change who may see it, or remove it (web app only) | `groups:write` |

## Examples

### GET /v1/church/groups

Groups, with how many are in each, who asked to join and when they last met

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

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

### POST /v1/church/groups

Add a group

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

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/groups`, {
  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/groups/$ID

A group: its members, who asked to join and its last meetings

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

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

### PATCH /v1/church/groups/$ID

Change a group, close it, or open it again

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

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/groups/${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();
```

### DELETE /v1/church/groups/$ID/meetings/$DAY

Remove a day's attendance

```bash
curl -s -X DELETE "https://api.chapelwren.com/v1/church/groups/$ID/meetings/$DAY" \
  -H "Authorization: Bearer $CG_API_KEY"
```

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

### PUT /v1/church/groups/$ID/meetings/$DAY

Who came to a group on a day. Sending it again corrects it

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

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/groups/${id}/meetings/${day}`, {
  method: "PUT",
  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/groups/$ID/members

Put someone in a group, or make a member its leader. `over` goes past the size limit

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

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/groups/${id}/members`, {
  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();
```

### DELETE /v1/church/groups/$ID/members/$PERSON

Take someone out of a group. Past attendance stays

```bash
curl -s -X DELETE "https://api.chapelwren.com/v1/church/groups/$ID/members/$PERSON" \
  -H "Authorization: Bearer $CG_API_KEY"
```

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

### POST /v1/church/groups/$ID/requests/$REQUEST

Say yes or no to someone who asked to join. Yes finds their record or adds them as a visitor

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

```js
const res = await fetch(`https://api.chapelwren.com/v1/church/groups/${id}/requests/${request}`, {
  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();
```

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).
