Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / docs / development / API / pleroma_api.md
1 # Pleroma API
2
3 Requests that require it can be authenticated with [an OAuth token](https://tools.ietf.org/html/rfc6749), the `_pleroma_key` cookie, or [HTTP Basic Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization).
4
5 Request parameters can be passed via [query strings](https://en.wikipedia.org/wiki/Query_string) or as [form data](https://www.w3.org/TR/html401/interact/forms.html). Files must be uploaded as `multipart/form-data`.
6
7 ## `/api/pleroma/emoji`
8 ### Lists the custom emoji on that server.
9 * Method: `GET`
10 * Authentication: not required
11 * Params: none
12 * Response: JSON
13 * Example response:
14 ```json
15 {
16 "girlpower": {
17 "tags": [
18 "Finmoji"
19 ],
20 "image_url": "/finmoji/128px/girlpower-128.png"
21 },
22 "education": {
23 "tags": [
24 "Finmoji"
25 ],
26 "image_url": "/finmoji/128px/education-128.png"
27 },
28 "finnishlove": {
29 "tags": [
30 "Finmoji"
31 ],
32 "image_url": "/finmoji/128px/finnishlove-128.png"
33 }
34 }
35 ```
36 * Note: Same data as Mastodon API’s `/api/v1/custom_emojis` but in a different format
37
38 ## `/api/pleroma/follow_import`
39 ### Imports your follows, for example from a Mastodon CSV file.
40 * Method: `POST`
41 * Authentication: required
42 * Params:
43 * `list`: STRING or FILE containing a whitespace-separated list of accounts to follow
44 * Response: HTTP 200 on success, 500 on error
45 * Note: Users that can't be followed are silently skipped.
46
47 ## `/api/pleroma/blocks_import`
48 ### Imports your blocks.
49 * Method: `POST`
50 * Authentication: required
51 * Params:
52 * `list`: STRING or FILE containing a whitespace-separated list of accounts to block
53 * Response: HTTP 200 on success, 500 on error
54
55 ## `/api/pleroma/mutes_import`
56 ### Imports your mutes.
57 * Method: `POST`
58 * Authentication: required
59 * Params:
60 * `list`: STRING or FILE containing a whitespace-separated list of accounts to mute
61 * Response: HTTP 200 on success, 500 on error
62
63 ## `/api/pleroma/captcha`
64 ### Get a new captcha
65 * Method: `GET`
66 * Authentication: not required
67 * Params: none
68 * Response: Provider specific JSON, the only guaranteed parameter is `type`
69 * Example response: `{"type": "kocaptcha", "token": "whatever", "url": "https://captcha.kotobank.ch/endpoint", "seconds_valid": 300}`
70
71 ## `/api/pleroma/delete_account`
72 ### Delete an account
73 * Method `POST`
74 * Authentication: required
75 * Params:
76 * `password`: user's password
77 * Response: JSON. Returns `{"status": "success"}` if the deletion was successful, `{"error": "[error message]"}` otherwise
78 * Example response: `{"error": "Invalid password."}`
79
80 ## `/api/pleroma/disable_account`
81 ### Disable an account
82 * Method `POST`
83 * Authentication: required
84 * Params:
85 * `password`: user's password
86 * Response: JSON. Returns `{"status": "success"}` if the account was successfully disabled, `{"error": "[error message]"}` otherwise
87 * Example response: `{"error": "Invalid password."}`
88
89 ## `/api/pleroma/accounts/mfa`
90 #### Gets current MFA settings
91 * method: `GET`
92 * Authentication: required
93 * OAuth scope: `read:security`
94 * Response: JSON. Returns `{"enabled": "false", "totp": false }`
95
96 ## `/api/pleroma/accounts/mfa/setup/totp`
97 #### Pre-setup the MFA/TOTP method
98 * method: `GET`
99 * Authentication: required
100 * OAuth scope: `write:security`
101 * Response: JSON. Returns `{"key": [secret_key], "provisioning_uri": "[qr code uri]" }` when successful, otherwise returns HTTP 422 `{"error": "error_msg"}`
102
103 ## `/api/pleroma/accounts/mfa/confirm/totp`
104 #### Confirms & enables MFA/TOTP support for user account.
105 * method: `POST`
106 * Authentication: required
107 * OAuth scope: `write:security`
108 * Params:
109 * `password`: user's password
110 * `code`: token from TOTP App
111 * Response: JSON. Returns `{}` if the enable was successful, HTTP 422 `{"error": "[error message]"}` otherwise
112
113
114 ## `/api/pleroma/accounts/mfa/totp`
115 #### Disables MFA/TOTP method for user account.
116 * method: `DELETE`
117 * Authentication: required
118 * OAuth scope: `write:security`
119 * Params:
120 * `password`: user's password
121 * Response: JSON. Returns `{}` if the disable was successful, HTTP 422 `{"error": "[error message]"}` otherwise
122 * Example response: `{"error": "Invalid password."}`
123
124 ## `/api/pleroma/accounts/mfa/backup_codes`
125 #### Generstes backup codes MFA for user account.
126 * method: `GET`
127 * Authentication: required
128 * OAuth scope: `write:security`
129 * Response: JSON. Returns `{"codes": codes}`when successful, otherwise HTTP 422 `{"error": "[error message]"}`
130
131 ## `/api/pleroma/admin/`
132 See [Admin-API](admin_api.md)
133
134 ## `/api/v1/pleroma/notifications/read`
135 ### Mark notifications as read
136 * Method `POST`
137 * Authentication: required
138 * Params (mutually exclusive):
139 * `id`: a single notification id to read
140 * `max_id`: read all notifications up to this id
141 * Response: Notification entity/Array of Notification entities that were read. In case of `max_id`, only the first 80 read notifications will be returned.
142
143 ## `/api/v1/pleroma/accounts/:id/subscribe`
144 ### Subscribe to receive notifications for all statuses posted by a user
145 * Method `POST`
146 * Authentication: required
147 * Params:
148 * `id`: account id to subscribe to
149 * Response: JSON, returns a mastodon relationship object on success, otherwise returns `{"error": "error_msg"}`
150 * Example response:
151 ```json
152 {
153 "id": "abcdefg",
154 "following": true,
155 "followed_by": false,
156 "blocking": false,
157 "muting": false,
158 "muting_notifications": false,
159 "subscribing": true,
160 "requested": false,
161 "domain_blocking": false,
162 "showing_reblogs": true,
163 "endorsed": false
164 }
165 ```
166
167 ## `/api/v1/pleroma/accounts/:id/unsubscribe`
168 ### Unsubscribe to stop receiving notifications from user statuses
169 * Method `POST`
170 * Authentication: required
171 * Params:
172 * `id`: account id to unsubscribe from
173 * Response: JSON, returns a mastodon relationship object on success, otherwise returns `{"error": "error_msg"}`
174 * Example response:
175 ```json
176 {
177 "id": "abcdefg",
178 "following": true,
179 "followed_by": false,
180 "blocking": false,
181 "muting": false,
182 "muting_notifications": false,
183 "subscribing": false,
184 "requested": false,
185 "domain_blocking": false,
186 "showing_reblogs": true,
187 "endorsed": false
188 }
189 ```
190
191 ## `/api/v1/pleroma/accounts/:id/favourites`
192 ### Returns favorites timeline of any user
193 * Method `GET`
194 * Authentication: not required
195 * Params:
196 * `id`: the id of the account for whom to return results
197 * `limit`: optional, the number of records to retrieve
198 * `since_id`: optional, returns results that are more recent than the specified id
199 * `max_id`: optional, returns results that are older than the specified id
200 * Response: JSON, returns a list of Mastodon Status entities on success, otherwise returns `{"error": "error_msg"}`
201 * Example response:
202 ```json
203 [
204 {
205 "account": {
206 "id": "9hptFmUF3ztxYh3Svg",
207 "url": "https://pleroma.example.org/users/nick2",
208 "username": "nick2",
209 ...
210 },
211 "application": {"name": "Web", "website": null},
212 "bookmarked": false,
213 "card": null,
214 "content": "This is :moominmamma: note 0",
215 "created_at": "2019-04-15T15:42:15.000Z",
216 "emojis": [],
217 "favourited": false,
218 "favourites_count": 1,
219 "id": "9hptFmVJ02khbzYJaS",
220 "in_reply_to_account_id": null,
221 "in_reply_to_id": null,
222 "language": null,
223 "media_attachments": [],
224 "mentions": [],
225 "muted": false,
226 "pinned": false,
227 "pleroma": {
228 "content": {"text/plain": "This is :moominmamma: note 0"},
229 "conversation_id": 13679,
230 "local": true,
231 "spoiler_text": {"text/plain": "2hu"}
232 },
233 "reblog": null,
234 "reblogged": false,
235 "reblogs_count": 0,
236 "replies_count": 0,
237 "sensitive": false,
238 "spoiler_text": "2hu",
239 "tags": [{"name": "2hu", "url": "/tag/2hu"}],
240 "uri": "https://pleroma.example.org/objects/198ed2a1-7912-4482-b559-244a0369e984",
241 "url": "https://pleroma.example.org/notice/9hptFmVJ02khbzYJaS",
242 "visibility": "public"
243 }
244 ]
245 ```
246
247 ## `/api/v1/pleroma/accounts/update_*`
248 ### Set and clear account avatar, banner, and background
249
250 - PATCH `/api/v1/pleroma/accounts/update_avatar`: Set/clear user avatar image
251 - PATCH `/api/v1/pleroma/accounts/update_banner`: Set/clear user banner image
252 - PATCH `/api/v1/pleroma/accounts/update_background`: Set/clear user background image
253
254 ## `/api/v1/pleroma/accounts/confirmation_resend`
255 ### Resend confirmation email
256 * Method `POST`
257 * Params:
258 * `email`: email of that needs to be verified
259 * Authentication: not required
260 * Response: 204 No Content
261
262 ## `/api/v1/pleroma/mascot`
263 ### Gets user mascot image
264 * Method `GET`
265 * Authentication: required
266
267 * Response: JSON. Returns a mastodon media attachment entity.
268 * Example response:
269 ```json
270 {
271 "id": "abcdefg",
272 "url": "https://pleroma.example.org/media/abcdefg.png",
273 "type": "image",
274 "pleroma": {
275 "mime_type": "image/png"
276 }
277 }
278 ```
279
280 ### Updates user mascot image
281 * Method `PUT`
282 * Authentication: required
283 * Params:
284 * `file`: Multipart image
285 * Response: JSON. Returns a mastodon media attachment entity
286 when successful, otherwise returns HTTP 415 `{"error": "error_msg"}`
287 * Example response:
288 ```json
289 {
290 "id": "abcdefg",
291 "url": "https://pleroma.example.org/media/abcdefg.png",
292 "type": "image",
293 "pleroma": {
294 "mime_type": "image/png"
295 }
296 }
297 ```
298 * Note: Behaves exactly the same as `POST /api/v1/upload`.
299 Can only accept images - any attempt to upload non-image files will be met with `HTTP 415 Unsupported Media Type`.
300
301 ## `/api/pleroma/notification_settings`
302 ### Updates user notification settings
303 * Method `PUT`
304 * Authentication: required
305 * Params:
306 * `block_from_strangers`: BOOLEAN field, blocks notifications from accounts you do not follow
307 * `hide_notification_contents`: BOOLEAN field. When set to true, it removes the contents of a message from the push notification.
308 * Response: JSON. Returns `{"status": "success"}` if the update was successful, otherwise returns `{"error": "error_msg"}`
309
310 ## `/api/pleroma/healthcheck`
311 ### Healthcheck endpoint with additional system data.
312 * Method `GET`
313 * Authentication: not required
314 * Params: none
315 * Response: JSON, statuses (200 - healthy, 503 unhealthy).
316 * Example response:
317 ```json
318 {
319 "pool_size": 0, # database connection pool
320 "active": 0, # active processes
321 "idle": 0, # idle processes
322 "memory_used": 0.00, # Memory used
323 "healthy": true, # Instance state
324 "job_queue_stats": {} # Job queue stats
325 }
326 ```
327
328 ## `/api/pleroma/change_email`
329 ### Change account email
330 * Method `POST`
331 * Authentication: required
332 * Params:
333 * `password`: user's password
334 * `email`: new email
335 * Response: JSON. Returns `{"status": "success"}` if the change was successful, `{"error": "[error message]"}` otherwise
336 * Note: Currently, Mastodon has no API for changing email. If they add it in future it might be incompatible with Pleroma.
337
338 # Pleroma Conversations
339
340 Pleroma Conversations have the same general structure that Mastodon Conversations have. The behavior differs in the following ways when using these endpoints:
341
342 1. Pleroma Conversations never add or remove recipients, unless explicitly changed by the user.
343 2. Pleroma Conversations statuses can be requested by Conversation id.
344 3. Pleroma Conversations can be replied to.
345
346 Conversations have the additional field `recipients` under the `pleroma` key. This holds a list of all the accounts that will receive a message in this conversation.
347
348 The status posting endpoint takes an additional parameter, `in_reply_to_conversation_id`, which, when set, will set the visiblity to direct and address only the people who are the recipients of that Conversation.
349
350 âš  Conversation IDs can be found in direct messages with the `pleroma.direct_conversation_id` key, do not confuse it with `pleroma.conversation_id`.
351
352 ## `GET /api/v1/pleroma/conversations/:id/statuses`
353 ### Timeline for a given conversation
354 * Method `GET`
355 * Authentication: required
356 * Params: Like other timelines
357 * Response: JSON, statuses (200 - healthy, 503 unhealthy).
358
359 ## `GET /api/v1/pleroma/conversations/:id`
360 ### The conversation with the given ID.
361 * Method `GET`
362 * Authentication: required
363 * Params: None
364 * Response: JSON, statuses (200 - healthy, 503 unhealthy).
365
366 ## `PATCH /api/v1/pleroma/conversations/:id`
367 ### Update a conversation. Used to change the set of recipients.
368 * Method `PATCH`
369 * Authentication: required
370 * Params:
371 * `recipients`: A list of ids of users that should receive posts to this conversation. This will replace the current list of recipients, so submit the full list. The owner of owner of the conversation will always be part of the set of recipients, though.
372 * Response: JSON, statuses (200 - healthy, 503 unhealthy)
373
374 ## `POST /api/v1/pleroma/conversations/read`
375 ### Marks all user's conversations as read.
376 * Method `POST`
377 * Authentication: required
378 * Params: None
379 * Response: JSON, returns a list of Mastodon Conversation entities that were marked as read (200 - healthy, 503 unhealthy).
380
381 ## `GET /api/pleroma/emoji/pack?name=:name`
382
383 ### Get pack.json for the pack
384
385 * Method `GET`
386 * Authentication: not required
387 * Params:
388 * `page`: page number for files (default 1)
389 * `page_size`: page size for files (default 30)
390 * Response: JSON, pack json with `files`, `files_count` and `pack` keys with 200 status or 404 if the pack does not exist.
391
392 ```json
393 {
394 "files": {...},
395 "files_count": 0, // emoji count in pack
396 "pack": {...}
397 }
398 ```
399
400 ## `POST /api/pleroma/emoji/pack?name=:name`
401
402 ### Creates an empty pack
403
404 * Method `POST`
405 * Authentication: required (admin)
406 * Params:
407 * `name`: pack name
408 * Response: JSON, "ok" and 200 status or 409 if the pack with that name already exists
409
410 ## `PATCH /api/pleroma/emoji/pack?name=:name`
411
412 ### Updates (replaces) pack metadata
413
414 * Method `PATCH`
415 * Authentication: required (admin)
416 * Params:
417 * `name`: pack name
418 * `metadata`: metadata to replace the old one
419 * `license`: Pack license
420 * `homepage`: Pack home page url
421 * `description`: Pack description
422 * `fallback-src`: Fallback url to download pack from
423 * `fallback-src-sha256`: SHA256 encoded for fallback pack archive
424 * `share-files`: is pack allowed for sharing (boolean)
425 * Response: JSON, updated "metadata" section of the pack and 200 status or 400 if there was a
426 problem with the new metadata (the error is specified in the "error" part of the response JSON)
427
428 ## `DELETE /api/pleroma/emoji/pack?name=:name`
429
430 ### Delete a custom emoji pack
431
432 * Method `DELETE`
433 * Authentication: required (admin)
434 * Params:
435 * `name`: pack name
436 * Response: JSON, "ok" and 200 status or 500 if there was an error deleting the pack
437
438 ## `GET /api/pleroma/emoji/packs/import`
439
440 ### Imports packs from filesystem
441
442 * Method `GET`
443 * Authentication: required (admin)
444 * Params: None
445 * Response: JSON, returns a list of imported packs.
446
447 ## `GET /api/pleroma/emoji/packs/remote`
448
449 ### Make request to another instance for packs list
450
451 * Method `GET`
452 * Authentication: required (admin)
453 * Params:
454 * `url`: url of the instance to get packs from
455 * `page`: page number for packs (default 1)
456 * `page_size`: page size for packs (default 50)
457 * Response: JSON with the pack list, hashmap with pack name and pack contents
458
459 ## `POST /api/pleroma/emoji/packs/download`
460
461 ### Download pack from another instance
462
463 * Method `POST`
464 * Authentication: required (admin)
465 * Params:
466 * `url`: url of the instance to download from
467 * `name`: pack to download from that instance
468 * `as`: (*optional*) name how to save pack
469 * Response: JSON, "ok" with 200 status if the pack was downloaded, or 500 if there were
470 errors downloading the pack
471
472 ## `POST /api/pleroma/emoji/packs/files?name=:name`
473
474 ### Add new file to the pack
475
476 * Method `POST`
477 * Authentication: required (admin)
478 * Params:
479 * `name`: pack name
480 * `file`: file needs to be uploaded with the multipart request or link to remote file.
481 * `shortcode`: (*optional*) shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename.
482 * `filename`: (*optional*) new emoji file name. If not specified will be taken from original filename.
483 * Response: JSON, list of files for updated pack (hashmap -> shortcode => filename) with status 200, either error status with error message.
484
485 ## `PATCH /api/pleroma/emoji/packs/files?name=:name`
486
487 ### Update emoji file from pack
488
489 * Method `PATCH`
490 * Authentication: required (admin)
491 * Params:
492 * `name`: pack name
493 * `shortcode`: emoji file shortcode
494 * `new_shortcode`: new emoji file shortcode
495 * `new_filename`: new filename for emoji file
496 * `force`: (*optional*) with true value to overwrite existing emoji with new shortcode
497 * Response: JSON, list with updated files for updated pack (hashmap -> shortcode => filename) with status 200, either error status with error message.
498
499 ## `DELETE /api/pleroma/emoji/packs/files?name=:name`
500
501 ### Delete emoji file from pack
502
503 * Method `DELETE`
504 * Authentication: required (admin)
505 * Params:
506 * `name`: pack name
507 * `shortcode`: emoji file shortcode
508 * Response: JSON, list with updated files for updated pack (hashmap -> shortcode => filename) with status 200, either error status with error message.
509
510 ## `GET /api/pleroma/emoji/packs`
511
512 ### Lists local custom emoji packs
513
514 * Method `GET`
515 * Authentication: not required
516 * Params:
517 * `page`: page number for packs (default 1)
518 * `page_size`: page size for packs (default 50)
519 * Response: `packs` key with JSON hashmap of pack name to pack contents and `count` key for count of packs.
520
521 ```json
522 {
523 "packs": {
524 "pack_name": {...}, // pack contents
525 ...
526 },
527 "count": 0 // packs count
528 }
529 ```
530
531 ## `GET /api/pleroma/emoji/packs/archive?name=:name`
532
533 ### Requests a local pack archive from the instance
534
535 * Method `GET`
536 * Authentication: not required
537 * Params:
538 * `name`: pack name
539 * Response: the archive of the pack with a 200 status code, 403 if the pack is not set as shared,
540 404 if the pack does not exist
541
542 ## `GET /api/v1/pleroma/accounts/:id/scrobbles`
543 ### Requests a list of current and recent Listen activities for an account
544 * Method `GET`
545 * Authentication: not required
546 * Params: None
547 * Response: An array of media metadata entities.
548 * Example response:
549 ```json
550 [
551 {
552 "account": {...},
553 "id": "1234",
554 "title": "Some Title",
555 "artist": "Some Artist",
556 "album": "Some Album",
557 "length": 180000,
558 "created_at": "2019-09-28T12:40:45.000Z"
559 }
560 ]
561 ```
562
563 ## `POST /api/v1/pleroma/scrobble`
564 ### Creates a new Listen activity for an account
565 * Method `POST`
566 * Authentication: required
567 * Params:
568 * `title`: the title of the media playing
569 * `album`: the album of the media playing [optional]
570 * `artist`: the artist of the media playing [optional]
571 * `length`: the length of the media playing [optional]
572 * Response: the newly created media metadata entity representing the Listen activity
573
574 # Emoji Reactions
575
576 Emoji reactions work a lot like favourites do. They make it possible to react to a post with a single emoji character. To detect the presence of this feature, you can check `pleroma_emoji_reactions` entry in the features list of nodeinfo.
577
578 ## `PUT /api/v1/pleroma/statuses/:id/reactions/:emoji`
579 ### React to a post with a unicode emoji
580 * Method: `PUT`
581 * Authentication: required
582 * Params: `emoji`: A unicode RGI emoji or a regional indicator
583 * Response: JSON, the status.
584
585 ## `DELETE /api/v1/pleroma/statuses/:id/reactions/:emoji`
586 ### Remove a reaction to a post with a unicode emoji
587 * Method: `DELETE`
588 * Authentication: required
589 * Params: `emoji`: A unicode RGI emoji or a regional indicator
590 * Response: JSON, the status.
591
592 ## `GET /api/v1/pleroma/statuses/:id/reactions`
593 ### Get an object of emoji to account mappings with accounts that reacted to the post
594 * Method: `GET`
595 * Authentication: optional
596 * Params: None
597 * Response: JSON, a list of emoji/account list tuples, sorted by emoji insertion date, in ascending order, e.g, the first emoji in the list is the oldest.
598 * Example Response:
599 ```json
600 [
601 {"name": "😀", "count": 2, "me": true, "accounts": [{"id" => "xyz.."...}, {"id" => "zyx..."}]},
602 {"name": "☕", "count": 1, "me": false, "accounts": [{"id" => "abc..."}]}
603 ]
604 ```
605
606 ## `GET /api/v1/pleroma/statuses/:id/reactions/:emoji`
607 ### Get an object of emoji to account mappings with accounts that reacted to the post for a specific emoji
608 * Method: `GET`
609 * Authentication: optional
610 * Params: None
611 * Response: JSON, a list of emoji/account list tuples
612 * Example Response:
613 ```json
614 [
615 {"name": "😀", "count": 2, "me": true, "accounts": [{"id" => "xyz.."...}, {"id" => "zyx..."}]}
616 ]
617 ```
618
619 ## `POST /api/v1/pleroma/backups`
620 ### Create a user backup archive
621
622 * Method: `POST`
623 * Authentication: required
624 * Params: none
625 * Response: JSON
626 * Example response:
627
628 ```json
629 [{
630 "content_type": "application/zip",
631 "file_size": 0,
632 "inserted_at": "2020-09-10T16:18:03.000Z",
633 "processed": false,
634 "url": "https://example.com/media/backups/archive-foobar-20200910T161803-QUhx6VYDRQ2wfV0SdA2Pfj_2CLM_ATUlw-D5l5TJf4Q.zip"
635 }]
636 ```
637
638 ## `GET /api/v1/pleroma/backups`
639 ### Lists user backups
640
641 * Method: `GET`
642 * Authentication: not required
643 * Params: none
644 * Response: JSON
645 * Example response:
646
647 ```json
648 [{
649 "content_type": "application/zip",
650 "file_size": 55457,
651 "inserted_at": "2020-09-10T16:18:03.000Z",
652 "processed": true,
653 "url": "https://example.com/media/backups/archive-foobar-20200910T161803-QUhx6VYDRQ2wfV0SdA2Pfj_2CLM_ATUlw-D5l5TJf4Q.zip"
654 }]
655 ```