sr.ht-docs/todo.sr.ht/api.md -rw-r--r-- 11.4 KiB View raw
                                                                                
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
---
title: todo.sr.ht API reference
---

The todo.sr.ht API allows you to browse, create, and manage repositories on
todo.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 todo.sr.ht:

- **events:read**: read ticket events
- **trackers:read**, **trackers:write**: read & write tracker details
- **tickets:read**, **tickets:write**: read & write tickets & comments

## Resources

### Comment resource

```json
{
  "id": integer,
  "created": "timestamp",
  "submitter": { short-form user resource },
  "text": "string (markdown)",
  "ticket" { short-form ticket resoruce }
}
```

Short form:

```json
{
  "id": integer,
  "created": "timestamp",
  "submitter": { short-form user resource },
  "text": "string (markdown)"
}
```

### Event resource

```json
{
  "id": integer,
  "created": "timestamp",
  "event_type": [ ...list of event types... ],
  "old_status": status or null,
  "old_resolution": resolution or null,
  "new_status": status or null,
  "new_resolution": resolution or null,
  "user": { short-form user resource } or null,
  "ticket": { short-form ticket resource } or null,
  "comment": { short-form comment resource } or null,
  "label": [ ...list of strings... ] or null,
  "by_user": { short-form user resource } or null,
  "from_ticket": { short-form ticket resource } or null
}
```

**Event type** may be one or more of `created`, `comment`, `status_change`,
`label_added`, `label_removed`, `assigned_user`, `unassigned_user`,
`user_mentioned`, or `ticket_mentioned`.

**Status** fields may be one of `reported`, `confirmed`, `in_progress`,
`pending`, or `resolved`.

**Resolution** fields may be one of `unresolved`, `fixed`, `implemented`,
`wont_fix`, `by_design`, `invalid`, `duplicate`, or `not_our_bug`.

The `by_user` and `from_ticket` features are used for events where a ticket or
user was mentioned in a comment somewhere. The ticket field and user field are
set to the mentioned ticket or user, and the `by_user` or `from_ticket` field
are set according to the discussion where the mention occured.

### Label resource

```json
{
  "name": "string",
  "created": "timestamp",
  "colors": {
    "background": "#rrggbb",
    "text": "#rrggbb"
  },
  "tracker": { short-form tracker resource }
}
```

Short form:

```json
{
  "name": "string",
  "colors": {
    "background": "#rrggbb",
    "text": "#rrggbb"
  }
}
```

### Ticket resource

```json
{
  "id": integer,
  "ref": "string",
  "tracker": { short-form tracker resource },
  "title": "ticket subject",
  "created": "timestamp",
  "updated": "timestamp",
  "submitter": { short-form user resource },
  "description": "string (markdown)",
  "status": status,
  "resolution": resolution,
  "permissions": {
    "anonymous": [ ...list of strings... ] or null,
    "submitter": [ ...list of strings... ] or null,
    "user": [ ...list of strings... ] or null,
  },
  "labels": [ ...list of label names... ],
  "assignees": [ ...list of short-form user resources... ]
}
```

**Status** fields may be one of `reported`, `confirmed`, `in_progress`,
`pending`, or `resolved`.

**Resolution** fields may be one of `unresolved`, `fixed`, `implemented`,
`wont_fix`, `by_design`, `invalid`, `duplicate`, or `not_our_bug`.

**Permissions** may be one or more of `browse`, `submit`, `comment`, `edit`, and
`triage`.  If null, the permissions are inherited from the tracker.

Short form:

```json
{
  "id": integer,
  "ref": "string",
  "tracker": { short-form tracker resource }
}
```

### Tracker resource

```json
{
  "owner": { short-form user resource },
  "created": "timestamp",
  "updated": "timestamp",
  "name": "string",
  "description": "string (markdown)",
  "default_permissions": {
    "anonymous": [ ...list of permissions... ],
    "submitter": [ ...list of permissions... ],
    "user": [ ...list of permissions... ]
  }
}
```

**Permissions** may be one or more of `browse`, `submit`, `comment`, `edit`, and
`triage`.

Short form:

```json
{
  "owner": { short-form user resource },
  "created": "timestamp",
  "updated": "timestamp",
  "name": "string",
}
```

## Endpoints

**Note**: usernames are prefixed with `~`.

### 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/trackers

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

**OAuth scope**: `trackers:read`

### GET /api/trackers

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

**OAuth scope**: `trackers:read`

### POST /api/trackers

Creates a new [tracker resource](#tracker-resource).

**OAuth scope**: `trackers:write`

**Request body**

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

**Response**

The new [tracker resource](#tracker-resource)

### GET /api/user/:username/trackers/:tracker-name

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

**OAuth scope**: `trackers:read`

### GET /api/trackers/:tracker-name

Equivalent to
[/api/:username/trackers/:tracker-name](#GET-apiusernametrackerstrackername),
implies the authenticated user.

**OAuth scope**: `trackers:read`

### PUT /api/user/:username/trackers/:tracker-name

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

```json
{
  "description": "tracker description (markdown)" (optional)
}
```

**OAuth scope**: `trackers:write`

### PUT /api/trackers/:tracker-name

Equivalent to
[/api/:username/trackers/:tracker-name](#PUT-apiusernametrackerstrackername),
implies the authenticated user.

**OAuth scope**: `trackers:write`

### DELETE /api/trackers/:tracker-name

Deletes a [tracker resource](#tracker-resource).

**OAuth scope**: `trackers:write`

### DELETE /api/trackers/:tracker-name

Equivalent to
[/api/:username/trackers/:tracker-name](#DELETE-apiusernametrackerstrackername),
implies the authenticated user.

**OAuth scope**: `trackers:write`

### GET /api/user/:username/trackers/:tracker-name/labels

List of [label resources](#label-resource) associated with this tracker.

**OAuth scope**: `trackers:read`

### GET /api/trackers/:tracker-name/labels

Equivalent to
[/api/:username/trackers/:tracker-name/labels](#GET-apiusernametrackerstrackernamelabels),
implies the authenticated user.

**OAuth scope**: `trackers:read`

### GET /api/user/:username/trackers/:tracker-name/tickets

List of [ticket resources](#ticket-resource) associated with this tracker.

**OAuth scope**: `tickets:read`

### GET /api/trackers/:tracker-name/tickets

Equivalent to
[/api/:username/trackers/:tracker-name/tickets](#GET-apiusernametrackerstrackernametickets),
implies the authenticated user.

**OAuth scope**: `tickets:read`

### POST /api/user/:username/trackers/:tracker-name/tickets

Creates a new [ticket resources](#ticket-resource) associated with this tracker.

**OAuth scope**: `tickets:write`

**Request body**

```json
{
  "title": "ticket title",
  "description": "ticket description (markdown)" (optional)
}
```

**Response**

The new [ticket resource](#ticket-resource)

### POST /api/trackers/:tracker-name/tickets

Equivalent to
[/api/:username/trackers/:tracker-name/tickets](#POST-apiusernametrackerstrackernametickets),
implies the authenticated user.

**OAuth scope**: `tickets:write`

### GET /api/user/:username/trackers/:tracker-name/tickets/:ticket-id

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

**OAuth scope**: `tickets:read`

### GET /api/trackers/:tracker-name/tickets/:ticket-id

Equivalent to
[/api/:username/trackers/:tracker-name/tickets/:ticket-id](#GET-apiusernametrackerstrackernameticketsticketid),
implies the authenticated user.

**OAuth scope**: `tickets:read`

### PUT /api/user/:username/trackers/:tracker-name/tickets/:ticket-id

Updates a [ticket resource](#ticket-resource). This endpoint is used to:

- Open or close tickets
- Comment on tickets
- Add or remove labels

**OAuth scope**: `tickets:write`

**Request body**

```json
{
  "comment": "comment text (markdown)" (optional),
  "status": "ticket status enum" (optional),
  "resolution": "ticket resolution enum" (optional),
  "labels": ["list of desired label names"] (optional)
}
```

**Ticket status enum**

One of:

- `reported`
- `confirmed`
- `in_progress`
- `pending`
- `resolved`

**Ticket resolution enum**

One of:

- `unresolved`
- `fixed`
- `implemented`
- `wont_fix`
- `by_design`
- `invalid`
- `duplicate`
- `not_our_bug`

**Response**

```json
{
  "ticket": { affected ticket resource },
  "events": [
    list of event resources created by this update
  ]
}
```

### PUT /api/trackers/:tracker-name/tickets/:ticket-id

Equivalent to
[/api/:username/trackers/:tracker-name/tickets/:ticket-id](#PUT-apiusernametrackerstrackernameticketsticketid),
implies the authenticated user.

**OAuth scope**: `tickets:write`

### GET /api/user/:username/trackers/:tracker-name/tickets/:ticket-id/events

List of [event resources](#event-resource) associated with this ticket.

**OAuth scope**: `tickets:read`

### GET /api/trackers/:tracker-name/tickets/:ticket-id/events

Equivalent to
[/api/:username/trackers/:tracker-name/tickets/:ticket-id/events](#GET-apiusernametrackerstrackernameticketsticketidevents),
implies the authenticated user.

**OAuth scope**: `tickets:read`

## Webhooks

### /api/user/...

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

#### tracker:create

Issued when the user creates a new tracker.

**OAuth scope**: `trackers:read`

**Request body**

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

#### tracker:update

Issued when the user updates a tracker.

**OAuth scope**: `trackers:read`

**Request body**

The affected [tracker resource](#tracker-resource).

#### tracker:delete

Issued when the user deletes a tracker.

**OAuth scope**: `trackers:read`

**Request body**

```json
{
  "id": the affected tracker ID
}
```

#### ticket:create

Issued when the user creates a new ticket.

**OAuth scope**: `tickets:read`

**Request body**

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

#### event:create

Issued when a new event is created for a ticket on this tracker.

**OAuth scope**: `tickets:read`

**Request body**

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

### /api/user/:username/trackers/:tracker-name

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

#### label:create

Issued when a new label is added to this tracker.

**OAuth scope**: `trackers:read`

**Request body**

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

#### label:delete

Issued when a label is removed from this tracker.

**OAuth scope**: `trackers:read`

**Request body**

```json
{
  "id": affected label ID
}
```

#### ticket:create

Issued when a ticket is created for this tracker.

**OAuth scope**: `tickets:read`

**Request body**

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

### /api/user/:username/trackers/:tracker-name/tickets/:ticket-id

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

#### ticket:update

Issued when this tickets details are updated.

**OAuth scope**: `tickets:read`

**Request body**

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

#### event:create

Issued when a new event is created for this this ticket.

**OAuth scope**: `tickets:read`

**Request body**

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