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.

294 lines
8.4 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. - `spoiler_text` (optional): text to be shown as a warning before the actual content
  43. Returns the new status.
  44. **POST /api/v1/media**
  45. Form data:
  46. - `file`: Image to be uploaded
  47. Returns a media object with an ID that can be attached when creating a status (see above).
  48. ### Retrieving a timeline
  49. **GET /api/v1/timelines/home**
  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. **GET /api/v1/notifications/:id**
  60. Returns single notification.
  61. **POST /api/v1/notifications/clear**
  62. Clears all of user's notifications.
  63. ### Following a remote user
  64. **POST /api/v1/follows**
  65. Form data:
  66. - uri: username@domain of the person you want to follow
  67. Returns the local representation of the followed account.
  68. ### Fetching data
  69. **GET /api/v1/statuses/:id**
  70. Returns status.
  71. **GET /api/v1/accounts/:id**
  72. Returns account.
  73. **GET /api/v1/accounts/verify_credentials**
  74. Returns authenticated user's account.
  75. **GET /api/v1/accounts/:id/statuses**
  76. Returns statuses by user. Same options as timeline are permitted.
  77. **GET /api/v1/accounts/:id/following**
  78. Returns users the given user is following.
  79. **GET /api/v1/accounts/:id/followers**
  80. Returns users the given user is followed by.
  81. **GET /api/v1/accounts/relationships**
  82. Returns relationships (`following`, `followed_by`, `blocking`) of the current user to a list of given accounts.
  83. Query parameters:
  84. - `id` (can be array): Account IDs
  85. **GET /api/v1/accounts/search**
  86. Returns matching accounts. Will lookup an account remotely if the search term is in the username@domain format and not yet in the database.
  87. Query parameters:
  88. - `q`: what to search for
  89. - `limit`: maximum number of matching accounts to return
  90. **GET /api/v1/blocks**
  91. Returns accounts blocked by authenticated user.
  92. **GET /api/v1/favourites**
  93. Returns statuses favourited by authenticated user.
  94. ### Deleting a status
  95. **DELETE /api/v1/statuses/:id**
  96. Returns an empty object.
  97. ### Reblogging a status
  98. **POST /api/v1/statuses/:id/reblog**
  99. Returns a new status that wraps around the reblogged one.
  100. ### Unreblogging a status
  101. **POST /api/v1/statuses/:id/unreblog**
  102. Returns the status that used to be reblogged.
  103. ### Favouriting a status
  104. **POST /api/v1/statuses/:id/favourite**
  105. Returns the target status.
  106. ### Unfavouriting a status
  107. **POST /api/v1/statuses/:id/unfavourite**
  108. Returns the target status.
  109. ### Threads
  110. **GET /api/v1/statuses/:id/context**
  111. Returns `ancestors` and `descendants` of the status.
  112. ### Who reblogged/favourited a status
  113. **GET /api/v1/statuses/:id/reblogged_by**
  114. **GET /api/v1/statuses/:id/favourited_by**
  115. Returns list of accounts.
  116. ### Following and unfollowing users
  117. **POST /api/v1/accounts/:id/follow**
  118. **POST /api/v1/accounts/:id/unfollow**
  119. Returns the updated relationship to the user.
  120. ### Blocking and unblocking users
  121. **POST /api/v1/accounts/:id/block**
  122. **POST /api/v1/accounts/:id/unblock**
  123. Returns the updated relationship to the user.
  124. ### OAuth apps
  125. **POST /api/v1/apps**
  126. Form data:
  127. - `client_name`: Name of your application
  128. - `redirect_uris`: Where the user should be redirected after authorization (for no redirect, use `urn:ietf:wg:oauth:2.0:oob`)
  129. - `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)
  130. - `website`: (optional) URL to the homepage of your app
  131. 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).
  132. 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.
  133. ___
  134. ## Entities
  135. ### Status
  136. | Attribute | Description |
  137. |---------------------|-------------|
  138. | `id` ||
  139. | `uri` | fediverse-unique resource ID |
  140. | `url` | URL to the status page (can be remote) |
  141. | `account` | Account |
  142. | `in_reply_to_id` | null or ID of status it replies to |
  143. | `reblog` | null or Status|
  144. | `content` | Body of the status. This will contain HTML (remote HTML already sanitized) |
  145. | `created_at` ||
  146. | `reblogs_count` ||
  147. | `favourites_count` ||
  148. | `reblogged` | Boolean for authenticated user |
  149. | `favourited` | Boolean for authenticated user |
  150. | `sensitive` | Boolean, true if media attachments should be hidden by default |
  151. | `spoiler_text` | If not empty, warning text that should be displayed before the actual content |
  152. | `visibility` | Either `public`, `unlisted` or `private` |
  153. | `media_attachments` | array of MediaAttachments |
  154. | `mentions` | array of Mentions |
  155. | `application` | Application from which the status was posted |
  156. Media Attachment:
  157. | Attribute | Description |
  158. |---------------------|-------------|
  159. | `url` | URL of the original image (can be remote) |
  160. | `preview_url` | URL of the preview image |
  161. | `type` | Image or video |
  162. Mention:
  163. | Attribute | Description |
  164. |---------------------|-------------|
  165. | `url` | URL of user's profile (can be remote) |
  166. | `acct` | Username for local or username@domain for remote users |
  167. | `id` | Account ID |
  168. Application:
  169. | Attribute | Description |
  170. |---------------------|-------------|
  171. | `name` | Name of the app |
  172. | `website` | Homepage URL of the app |
  173. ### Account
  174. | Attribute | Description |
  175. |-------------------|-------------|
  176. | `id` ||
  177. | `username` ||
  178. | `acct` | Equals username for local users, includes @domain for remote ones |
  179. | `display_name` ||
  180. | `note` | Biography of user |
  181. | `url` | URL of the user's profile page (can be remote) |
  182. | `avatar` | URL to the avatar image |
  183. | `header` | URL to the header image |
  184. | `locked` | Boolean for when the account cannot be followed without waiting for approval first |
  185. | `followers_count` ||
  186. | `following_count` ||
  187. | `statuses_count` ||
  188. ## Pagination
  189. 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)