You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
7.9 KiB

  1. API overview
  2. ============
  3. ## Contents
  4. - [Available libraries](#available-libraries)
  5. - [Notes](#notes)
  6. - [Methods](#methods)
  7. - Posting a status
  8. - Uploading media
  9. - Retrieving a timeline
  10. - Retrieving notifications
  11. - Following a remote user
  12. - Fetching data
  13. - Deleting a status
  14. - Reblogging a status
  15. - Favouriting a status
  16. - Threads (status context)
  17. - Who reblogged/favourited a status
  18. - Following/unfollowing accounts
  19. - Blocking/unblocking accounts
  20. - Creating OAuth apps
  21. - [Entities](#entities)
  22. - Status
  23. - Account
  24. - [Pagination](#pagination)
  25. ## Available libraries
  26. - [For Ruby](https://github.com/tootsuite/mastodon-api)
  27. - [For Python](https://github.com/halcy/Mastodon.py)
  28. - [For JavaScript](https://github.com/Zatnosk/libodonjs)
  29. - [For JavaScript (Node.js)](https://github.com/jessicahayley/node-mastodon)
  30. ## Notes
  31. When an array parameter is mentioned, the Rails convention of specifying array parameters in query strings is meant. For example, a ruby array like `foo = [1, 2, 3]` can be encoded in the params as `foo[]=1&foo[]=2&foo[]=3`. Square brackets can be indexed but can also be empty.
  32. When a file parameter is mentioned, a form-encoded upload is expected.
  33. ## Methods
  34. ### Posting a new status
  35. **POST /api/v1/statuses**
  36. Form data:
  37. - `status`: The text of the status
  38. - `in_reply_to_id` (optional): local ID of the status you want to reply to
  39. - `media_ids` (optional): array of media IDs to attach to the status (maximum 4)
  40. - `sensitive` (optional): set this to mark the media of the status as NSFW
  41. - `visibility` (optional): either `private`, `unlisted` or `public`
  42. Returns the new status.
  43. **POST /api/v1/media**
  44. Form data:
  45. - `file`: Image to be uploaded
  46. Returns a media object with an ID that can be attached when creating a status (see above).
  47. ### Retrieving a timeline
  48. **GET /api/v1/timelines/home**
  49. **GET /api/v1/timelines/mentions**
  50. **GET /api/v1/timelines/public**
  51. **GET /api/v1/timelines/tag/:hashtag**
  52. Returns statuses, most recent ones first. Home timeline is statuses from people you follow, mentions timeline is all statuses that mention you. Public timeline is "whole known network", and the last is the hashtag timeline.
  53. Query parameters:
  54. - `max_id` (optional): Skip statuses younger than ID (e.g. navigate backwards in time)
  55. - `since_id` (optional): Skip statuses older than ID (e.g. check for updates)
  56. ### Notifications
  57. **GET /api/v1/notifications**
  58. Returns notifications for the authenticated user. Each notification has an `id`, a `type` (mention, reblog, favourite, follow), an `account` which it came *from*, and in case of mention, reblog and favourite also a `status`.
  59. ### Following a remote user
  60. **POST /api/v1/follows**
  61. Form data:
  62. - uri: username@domain of the person you want to follow
  63. Returns the local representation of the followed account.
  64. ### Fetching data
  65. **GET /api/v1/statuses/:id**
  66. Returns status.
  67. **GET /api/v1/accounts/:id**
  68. Returns account.
  69. **GET /api/v1/accounts/verify_credentials**
  70. Returns authenticated user's account.
  71. **GET /api/v1/accounts/:id/statuses**
  72. Returns statuses by user. Same options as timeline are permitted.
  73. **GET /api/v1/accounts/:id/following**
  74. Returns users the given user is following.
  75. **GET /api/v1/accounts/:id/followers**
  76. Returns users the given user is followed by.
  77. **GET /api/v1/accounts/relationships**
  78. Returns relationships (`following`, `followed_by`, `blocking`) of the current user to a list of given accounts.
  79. Query parameters:
  80. - `id` (can be array): Account IDs
  81. **GET /api/v1/accounts/search**
  82. Returns matching accounts. Will lookup an account remotely if the search term is in the username@domain format and not yet in the database.
  83. Query parameters:
  84. - `q`: what to search for
  85. - `limit`: maximum number of matching accounts to return
  86. **GET /api/v1/blocks**
  87. Returns accounts blocked by authenticated user.
  88. **GET /api/v1/favourites**
  89. Returns statuses favourited by authenticated user.
  90. ### Deleting a status
  91. **DELETE /api/v1/statuses/:id**
  92. Returns an empty object.
  93. ### Reblogging a status
  94. **POST /api/v1/statuses/:id/reblog**
  95. Returns a new status that wraps around the reblogged one.
  96. ### Unreblogging a status
  97. **POST /api/v1/statuses/:id/unreblog**
  98. Returns the status that used to be reblogged.
  99. ### Favouriting a status
  100. **POST /api/v1/statuses/:id/favourite**
  101. Returns the target status.
  102. ### Unfavouriting a status
  103. **POST /api/v1/statuses/:id/unfavourite**
  104. Returns the target status.
  105. ### Threads
  106. **GET /api/v1/statuses/:id/context**
  107. Returns `ancestors` and `descendants` of the status.
  108. ### Who reblogged/favourited a status
  109. **GET /api/v1/statuses/:id/reblogged_by**
  110. **GET /api/v1/statuses/:id/favourited_by**
  111. Returns list of accounts.
  112. ### Following and unfollowing users
  113. **POST /api/v1/accounts/:id/follow**
  114. **POST /api/v1/accounts/:id/unfollow**
  115. Returns the updated relationship to the user.
  116. ### Blocking and unblocking users
  117. **POST /api/v1/accounts/:id/block**
  118. **POST /api/v1/accounts/:id/unblock**
  119. Returns the updated relationship to the user.
  120. ### OAuth apps
  121. **POST /api/v1/apps**
  122. Form data:
  123. - `client_name`: Name of your application
  124. - `redirect_uris`: Where the user should be redirected after authorization (for no redirect, use `urn:ietf:wg:oauth:2.0:oob`)
  125. - `scopes`: This can be a space-separated list of the following items: "read", "write" and "follow" (see [this page](OAuth-details.md) for details on what the scopes do)
  126. - `website`: (optional) URL to the homepage of your app
  127. Creates a new OAuth app. Returns `id`, `client_id` and `client_secret` which can be used with [OAuth authentication in your 3rd party app](Testing-with-cURL.md).
  128. These values should be requested in the app itself from the API for each new app install + mastodon domain combo, and stored in the app for future requests.
  129. ___
  130. ## Entities
  131. ### Status
  132. | Attribute | Description |
  133. |---------------------|-------------|
  134. | `id` ||
  135. | `uri` | fediverse-unique resource ID |
  136. | `url` | URL to the status page (can be remote) |
  137. | `account` | Account |
  138. | `in_reply_to_id` | null or ID of status it replies to |
  139. | `reblog` | null or Status|
  140. | `content` | Body of the status. This will contain HTML (remote HTML already sanitized) |
  141. | `created_at` ||
  142. | `reblogs_count` ||
  143. | `favourites_count` ||
  144. | `reblogged` | Boolean for authenticated user |
  145. | `favourited` | Boolean for authenticated user |
  146. | `media_attachments` | array of MediaAttachments |
  147. | `mentions` | array of Mentions |
  148. | `application` | Application from which the status was posted |
  149. Media Attachment:
  150. | Attribute | Description |
  151. |---------------------|-------------|
  152. | `url` | URL of the original image (can be remote) |
  153. | `preview_url` | URL of the preview image |
  154. | `type` | Image or video |
  155. Mention:
  156. | Attribute | Description |
  157. |---------------------|-------------|
  158. | `url` | URL of user's profile (can be remote) |
  159. | `acct` | Username for local or username@domain for remote users |
  160. | `id` | Account ID |
  161. Application:
  162. | Attribute | Description |
  163. |---------------------|-------------|
  164. | `name` | Name of the app |
  165. | `website` | Homepage URL of the app |
  166. ### Account
  167. | Attribute | Description |
  168. |-------------------|-------------|
  169. | `id` ||
  170. | `username` ||
  171. | `acct` | Equals username for local users, includes @domain for remote ones |
  172. | `display_name` ||
  173. | `note` | Biography of user |
  174. | `url` | URL of the user's profile page (can be remote) |
  175. | `avatar` | URL to the avatar image |
  176. | `header` | URL to the header image |
  177. | `followers_count` ||
  178. | `following_count` ||
  179. | `statuses_count` ||
  180. ## Pagination
  181. API methods that return collections of items can return a `Link` header containing URLs for the `next` and `prev` pages. [Link header RFC](https://tools.ietf.org/html/rfc5988)