aboutsummaryrefslogtreecommitdiffstats
path: root/lists.sr.ht/api.md
blob: 42a941f2425f60a4742e26acb1306fae1c32b419 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# API Reference

The lists.sr.ht API allows you to browse, create, and subscribe to mailing lists
on lists.sr.ht programmatically. This API follows the [standard sourcehut API
conventions](../api-conventions.md).

## Authentication

Authentication is done via the [meta.sr.ht OAuth
flow](https://man.sr.ht/meta.sr.ht/oauth-api.md). The following OAuth scopes are
available for lists.sr.ht:

- **emails:read**: read emails received from lists.sr.ht users
- **lists:read**, **list:write**: read & write your mailing lists
- **subs:read**, **subs:write**: read & write your subscriptions

## Resources

### Email resource

```json
{
  "id": integer,
  "created": "timestamp",
  "subject": "message subject",
  "message_id": "value of the Message-ID header",
  "parent_id": integer or null,
  "thread_id": integer,
  "list": { short form list resource },
  "sender": { short form user resource } or null,
  "is_patch": boolean,
  "is_request_pull": boolean,
  "replies": integer,
  "participants": integer,
  "envelope": "original email"
}
```

**Notes**

- The short form omits `is_patch`, `is_request_pull`, `replies`, `participants`,
  and `envelope`.
- The sender is null if the sender's email address could not be associated with
  a sr.ht account.

### Mailing list resource

```json
{
  "created": "timestamp",
  "updated": "timestamp",
  "name": "name of this list",
  "owner": { short form user resource },
  "description": "list description (markdown)",
  "permissions": {
    "nonsubscriber": [ list of permissions ],
    "subscriber": [ list of permissions ],
    "account": [ list of permissions ]
  }
}
```

**Notes**

- The permissions which may appear in each `permissions` field are "browse",
  "reply", and "post".
- The short form omits everything except for name and owner.

### Subscription resource

```json
{
  "id": integer,
  "created": "timestamp",
  "list": { short form list resource }
}
```

## Endpoints

**Note**: in all routes, `:username` may be substituted with an email address,
and `:email-id` may be the email's either of the "id" or "message_id" values.

### GET /api/:username

Retrieves a user resource.

### GET /api/user

Equivalent to [/api/:username](#GET-apiusername), implies the authenticated
user.

### GET /api/user/:username/emails

List of [email resources](#email-resource) received from this user.

**OAuth scope**: `emails:read`

### GET /api/user/emails

Equivalent to [/api/:username/emails](#GET-apiusernameemails), implies the
authenticated user.

**OAuth scope**: `emails:read`

### GET /api/emails/:email-id

Retrieves an [email resource](#email-resource).

**OAuth scope**: `emails:read`

### GET /api/user/:username/emails/:email-id

Equivalent to [GET /api/emails/:email-id](#GET-apiemailsemail-id); `username` is
discarded.

**OAuth scope**: `emails:read`

### GET /api/thread/:email-id

Retrieves an array of each email implicated in the thread identified by its
first message's `:email-id`.

**OAuth scope**: `emails:read`

**Response**

```json
[
  { short form email resource },
  ...
]
```

### GET /api/user/:username/thread/:email-id

Equivalent to [GET /api/thread/:email-id](#GET-apithreademail-id); `username` is
discarded.

**OAuth scope**: `emails:read`

### GET /api/user/:username/lists

List of [mailing list resources](#mailing-list-resource) owned by this user.

**OAuth scope**: `lists:read`

### GET /api/lists

Equivalent to [/api/:username/lists](#GET-apiusernamelists), implies the
authenticated user.

**OAuth scope**: `lists:read`

### POST /api/lists

Creates a new [mailing list resource](#mailing-list-resource).

**OAuth scope**: `lists:write`

**Request body**

```json
{
  "name": "mailing list name",
  "description": "mailing list description (markdown)" (optional)
}
```

**Response**

The new [mailing list resource](#mailing-list-resource).

### GET /api/user/:username/lists/:list-name

Retrieves a [mailing list resource](#mailing-list-resource).

**OAuth scope**: `lists:read`

### GET /api/lists/:list-name

Equivalent to [/api/:username/lists/:list-name](#GET-apiusernamelistslist-name),
implies the authenticated user.

**OAuth scope**: `lists:read`

### PUT /api/lists/:list-name

Updates a [mailing list resource](#mailing-list-resource).

**OAuth scope**: `lists:write`

**Request body**

```json
{
  "description": "mailing list description (markdown)" (optional)
}
```

**Response**

The updated [mailing list resource](#mailing-list-resource).

### GET /api/user/:username/lists/:list-name/posts

List of [email resources](#email-resource) posted to this list.

**OAuth scope**: `lists:read`

### GET /api/lists/:list-name/posts

Equivalent to
[/api/:username/lists/:list-name/posts](#GET-apiusernamelistslist-nameposts),
implies the authenticated user.

**OAuth scope**: `lists:read`

### GET /api/subscriptions

List of [subscription resources](#subscription-resources)

**OAuth scope**: `subs:read`

### POST /api/subscriptions

Create a new [subscription resources](#subscription-resources)

**OAuth scope**: `subs:write`

**Request body**

```json
{
  "list": "~owner/list-name"
}
```

**Response**

The new [subscription resource](#subscription-resource).

### GET /api/subscriptions/:sub-id

Retrieves a [subscription resource](#subscription-resource).

**OAuth scope**: `subs:read`

### DELETE /api/subscriptions/:sub-id

Deletes this [subscription resource](#subscription-resource).

**OAuth scope**: `subs:write`

## Webhooks

### /api/user/...

Webhook for user events. Includes the [standard webhook
endpoints](../api-conventions.md#webhooks)

#### email:received

Issued when lists.sr.ht receives an email from this user.

**OAuth scope**: `emails:read`

**Request body**

The new [email resource](#email-resource).

#### list:create

Issued when the user creates a new mailing list.

**OAuth scope**: `lists:read`

**Request body**

The new [mailing list resource](#mailing-list-resource).

#### subscription:create

Issued when the user subscribes to a mailing list.

**OAuth scope**: `subs:read`

**Request body**

The new [subscription resource](#subscription-resource).

#### subscription:remove

Issued when the user unsubscribes from a mailing list.

**OAuth scope**: `subs:read`

**Request body**

```json
{
  "id": integer ID of the affected subscription resource
}
```

### /api/user/:username/lists/:list-name/...

Webhook for mailing list events. Includes the [standard webhook
endpoints](../api-conventions.md#webhooks)

#### post:received

Issued when a new email is posted to this list.

**OAuth scope**: `lists:read`

**Request body**

The new [email resource](#email-resource).

#### list:update

Issued when the list details are updated.

**OAuth scope**: `lists:read`

**Request body**

The updated [mailing list resource](#mailing-list-resource).