aboutsummaryrefslogtreecommitdiffstats
path: root/lists.sr.ht/api.md
blob: 03384939a19c8277b6554b72c14a174cae05ab3b (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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
---
title: lists.sr.ht 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
- **patches:read**, **patches:write**: read & write patchsets on lists

## 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 }
}
```

### Patchset resource

```json
{
  "id": integer,
  "created": "timestamp",
  "updated": "timestamp",
  "subject": "patchset subject",
  "prefix": "subject prefix",
  "version": integer,
  "status": "patchset status enum",
  "list": { short form list resource },
  "cover_letter": { short form email resource } or null,
  "superseded_by": { short form patchset resource } or null
}
```

**Notes**

- The status field may be one of `proposed`, `needs_revision`, `superseded`,
  `approved`, `rejected`, or `applied`.
- The patchset subject is extracted from the cover letter if present, otherwise
  from the subject of the first patch.
- The subject prefix, in the example of `[PATCH foobar] Add foo to bar`, is
  "foobar".

## 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/user/:username

Retrieves a user resource.

### GET /api/user

Equivalent to [/api/user/:username](#GET-apiuserusername), 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/emails

Equivalent to [/api/user/:username/emails](#GET-apiuserusernameemails), 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/user/:username/lists](#GET-apiuserusernamelists), 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/user/:username/lists/:list-name](#GET-apiuserusernamelistslist-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/user/:username/lists/:list-name/posts](#GET-apiuserusernamelistslist-nameposts),
implies the authenticated user.

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

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

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

**OAuth scope**: `patches:read`

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

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

**OAuth scope**: `patches:read`

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

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

**OAuth scope**: `patches:read`

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

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

**OAuth scope**: `patches:read`

### PUT /api/user/:username/lists/:list-name/patchsets/:id

Updates a [patchset resource](#patchset-resource).

**OAuth scope**: `patches:read`

**Request body**

```json
{
  "status": "patchset status enum" (optional)
}
```

**Response**

The updated [patchset resource](#patchset-resource).

### PUT /api/user/:username/lists/:list-name/patchsets/:id

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

**OAuth scope**: `patches:read`

### GET /api/user/:username/lists/:list-name/patchsets/:id/patches

List of [email resources](#email-resource) making up the set of patches included
in this patchset.

**OAuth scope**: `patches:read`

### GET /api/user/:username/lists/:list-name/patchsets/:id/patches

Equivalent to
[/api/user/:username/lists/:list-name/patchsets/:id/patches](#GET-apiuserusernamelistslist-namepatchsetsidpatches),
implies the authenticated user.

**OAuth scope**: `patches: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)

#### patchset:received

Issued when a complete patchset is received.

**OAuth scope**: `patches:read`

**Request body**

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

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