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.

535 lines
16 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. API overview
  2. ============
  3. ## Contents
  4. - [Available libraries](#available-libraries)
  5. - [Notes](#notes)
  6. - [Methods](#methods)
  7. - [Accounts](#accounts)
  8. - [Apps](#apps)
  9. - [Blocks](#blocks)
  10. - [Favourites](#favourites)
  11. - [Follow Requests](#follow-requests)
  12. - [Follows](#follows)
  13. - [Instances](#instances)
  14. - [Media](#media)
  15. - [Mutes](#mutes)
  16. - [Notifications](#notifications)
  17. - [Reports](#reports)
  18. - [Search](#search)
  19. - [Statuses](#statuses)
  20. - [Timelines](#timelines)
  21. - [Entities](#entities)
  22. - [Account](#account)
  23. - [Application](#application)
  24. - [Attachment](#attachment)
  25. - [Card](#card)
  26. - [Context](#context)
  27. - [Error](#error)
  28. - [Instance](#instance)
  29. - [Mention](#mention)
  30. - [Notification](#notification)
  31. - [Relationship](#relationship)
  32. - [Results](#results)
  33. - [Status](#status)
  34. - [Tag](#tag)
  35. ___
  36. ## Available libraries
  37. - [For Ruby](https://github.com/tootsuite/mastodon-api)
  38. - [For Python](https://github.com/halcy/Mastodon.py)
  39. - [For JavaScript](https://github.com/Zatnosk/libodonjs)
  40. - [For JavaScript (Node.js)](https://github.com/jessicahayley/node-mastodon)
  41. - [For Elixir](https://github.com/milmazz/hunter)
  42. ___
  43. ## Notes
  44. ### Parameter types
  45. When an array parameter is mentioned, the Rails convention of specifying array parameters in query strings is meant.
  46. For example, a ruby array like `foo = [1, 2, 3]` can be encoded in the params as `foo[]=1&foo[]=2&foo[]=3`.
  47. Square brackets can be indexed but can also be empty.
  48. When a file parameter is mentioned, a form-encoded upload is expected.
  49. ### Selecting ranges
  50. For most `GET` operations that return arrays, the query parameters `max_id` and `since_id` can be used to specify the range of IDs to return.
  51. API methods that return collections of items can return a `Link` header containing URLs for the `next` and `prev` pages.
  52. See the [Link header RFC](https://tools.ietf.org/html/rfc5988) for more information.
  53. ### Errors
  54. If the request you make doesn't go through, Mastodon will usually respond with an [Error](#error).
  55. ___
  56. ## Methods
  57. ### Accounts
  58. #### Fetching an account:
  59. GET /api/v1/accounts/:id
  60. Returns an [Account](#account).
  61. #### Getting the current user:
  62. GET /api/v1/accounts/verify_credentials
  63. Returns the authenticated user's [Account](#account).
  64. #### Updating the current user:
  65. PATCH /api/v1/accounts/update_credentials
  66. Form data:
  67. - `display_name`: The name to display in the user's profile
  68. - `note`: A new biography for the user
  69. - `avatar`: A base64 encoded image to display as the user's avatar (e.g. `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUoAAADrCAYAAAA...`)
  70. - `header`: A base64 encoded image to display as the user's header image (e.g. `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUoAAADrCAYAAAA...`)
  71. #### Getting an account's followers:
  72. GET /api/v1/accounts/:id/followers
  73. Returns an array of [Accounts](#account).
  74. #### Getting who account is following:
  75. GET /api/v1/accounts/:id/following
  76. Returns an array of [Accounts](#account).
  77. #### Getting an account's statuses:
  78. GET /api/v1/accounts/:id/statuses
  79. Query parameters:
  80. - `only_media` (optional): Only return statuses that have media attachments
  81. - `exclude_replies` (optional): Skip statuses that reply to other statuses
  82. Returns an array of [Statuses](#status).
  83. #### Following/unfollowing an account:
  84. GET /api/v1/accounts/:id/follow
  85. GET /api/v1/accounts/:id/unfollow
  86. Returns the target [Account](#account).
  87. #### Blocking/unblocking an account:
  88. GET /api/v1/accounts/:id/block
  89. GET /api/v1/accounts/:id/unblock
  90. Returns the target [Account](#account).
  91. #### Muting/unmuting an account:
  92. GET /api/v1/accounts/:id/mute
  93. GET /api/v1/accounts/:id/unmute
  94. Returns the target [Account](#account).
  95. #### Getting an account's relationships:
  96. GET /api/v1/accounts/relationships
  97. Query parameters:
  98. - `id` (can be array): Account IDs
  99. Returns an array of [Relationships](#relationships) of the current user to a list of given accounts.
  100. #### Searching for accounts:
  101. GET /api/v1/accounts/search
  102. Query parameters:
  103. - `q`: What to search for
  104. - `limit`: Maximum number of matching accounts to return (default: `40`)
  105. Returns an array of matching [Accounts](#accounts).
  106. Will lookup an account remotely if the search term is in the `username@domain` format and not yet in the database.
  107. ### Apps
  108. #### Registering an application:
  109. POST /api/v1/apps
  110. Form data:
  111. - `client_name`: Name of your application
  112. - `redirect_uris`: Where the user should be redirected after authorization (for no redirect, use `urn:ietf:wg:oauth:2.0:oob`)
  113. - `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)
  114. - `website`: (optional) URL to the homepage of your app
  115. Creates a new OAuth app.
  116. Returns `id`, `client_id` and `client_secret` which can be used with [OAuth authentication in your 3rd party app](Testing-with-cURL.md).
  117. 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.
  118. ### Blocks
  119. #### Fetching a user's blocks:
  120. GET /api/v1/blocks
  121. Returns an array of [Accounts](#account) blocked by the authenticated user.
  122. ### Favourites
  123. #### Fetching a user's favourites:
  124. GET /api/v1/favourites
  125. Returns an array of [Statuses](#status) favourited by the authenticated user.
  126. ### Follow Requests
  127. #### Fetching a list of follow requests:
  128. GET /api/v1/follow_requests
  129. Returns an array of [Accounts](#account) which have requested to follow the authenticated user.
  130. #### Authorizing or rejecting follow requests:
  131. POST /api/v1/follow_requests/authorize
  132. POST /api/v1/follow_requests/reject
  133. Form data:
  134. - `id`: The id of the account to authorize or reject
  135. Returns an empty object.
  136. ### Follows
  137. #### Following a remote user:
  138. POST /api/v1/follows
  139. Form data:
  140. - `uri`: `username@domain` of the person you want to follow
  141. Returns the local representation of the followed account, as an [Account](#account).
  142. ### Instances
  143. #### Getting instance information:
  144. GET /api/v1/instance
  145. Returns the current [Instance](#instance).
  146. Does not require authentication.
  147. ### Media
  148. #### Uploading a media attachment:
  149. POST /api/v1/media
  150. Form data:
  151. - `file`: Media to be uploaded
  152. Returns an [Attachment](#attachment) that can be used when creating a status.
  153. ### Mutes
  154. #### Fetching a user's mutes:
  155. GET /api/v1/mutes
  156. Returns an array of [Accounts](#account) muted by the authenticated user.
  157. ### Notifications
  158. #### Fetching a user's notifications:
  159. GET /api/v1/notifications
  160. Returns a list of [Notifications](#notification) for the authenticated user.
  161. #### Getting a single notification:
  162. GET /api/v1/notifications/:id
  163. Returns the [Notification](#notification).
  164. #### Clearing notifications:
  165. POST /api/v1/notifications/clear
  166. Deletes all notifications from the Mastodon server for the authenticated user.
  167. Returns an empty object.
  168. ### Reports
  169. #### Fetching a user's reports:
  170. GET /api/v1/reports
  171. Returns a list of [Reports](#report) made by the authenticated user.
  172. #### Reporting a user:
  173. POST /api/v1/reports
  174. Form data:
  175. - `account_id`: The ID of the account to report
  176. - `status_ids`: The IDs of statuses to report (can be an array)
  177. - `comment`: A comment to associate with the report.
  178. Returns the finished [Report](#report).
  179. ### Search
  180. #### Searching for content:
  181. GET /api/v1/search
  182. Form data:
  183. - `q`: The search query
  184. - `resolve`: Whether to resolve non-local accounts
  185. Returns [Results](#results).
  186. If `q` is a URL, Mastodon will attempt to fetch the provided account or status.
  187. Otherwise, it will do a local account and hashtag search.
  188. ### Statuses
  189. #### Fetching a status:
  190. GET /api/v1/statuses/:id
  191. Returns a [Status](#status).
  192. #### Getting status context:
  193. GET /api/v1/statuses/:id/context
  194. Returns a [Context](#context).
  195. #### Getting a card associated with a status:
  196. GET /api/v1/statuses/:id/card
  197. Returns a [Card](#card).
  198. #### Getting who reblogged/favourited a status:
  199. GET /api/v1/statuses/:id/reblogged_by
  200. GET /api/v1/statuses/:id/favourited_by
  201. Returns an array of [Accounts](#account).
  202. #### Posting a new status:
  203. POST /api/v1/statuses
  204. Form data:
  205. - `status`: The text of the status
  206. - `in_reply_to_id` (optional): local ID of the status you want to reply to
  207. - `media_ids` (optional): array of media IDs to attach to the status (maximum 4)
  208. - `sensitive` (optional): set this to mark the media of the status as NSFW
  209. - `spoiler_text` (optional): text to be shown as a warning before the actual content
  210. - `visibility` (optional): either "direct", "private", "unlisted" or "public"
  211. Returns the new [Status](#status).
  212. #### Deleting a status:
  213. DELETE /api/v1/statuses/:id
  214. Returns an empty object.
  215. #### Reblogging/unreblogging a status:
  216. POST /api/v1/statuses/:id/reblog
  217. POST /api/v1/statuses/:id/unreblog
  218. Returns the target [Status](#status).
  219. #### Favouriting/unfavouriting a status:
  220. POST /api/v1/statuses/:id/favourite
  221. POST /api/v1/statuses/:id/unfavourite
  222. Returns the target [Status](#status).
  223. ### Timelines
  224. #### Retrieving a timeline:
  225. GET /api/v1/timelines/home
  226. GET /api/v1/timelines/public
  227. GET /api/v1/timelines/tag/:hashtag
  228. Query parameters:
  229. - `local` (optional; public and tag timelines only): Only return statuses originating from this instance
  230. Returns an array of [Statuses](#status), most recent ones first.
  231. ___
  232. ## Entities
  233. ### Account
  234. | Attribute | Description |
  235. | ------------------------ | ----------- |
  236. | `id` | The ID of the account |
  237. | `username` | The username of the account |
  238. | `acct` | Equals `username` for local users, includes `@domain` for remote ones |
  239. | `display_name` | The account's display name |
  240. | `note` | Biography of user |
  241. | `url` | URL of the user's profile page (can be remote) |
  242. | `avatar` | URL to the avatar image |
  243. | `header` | URL to the header image |
  244. | `locked` | Boolean for when the account cannot be followed without waiting for approval first |
  245. | `created_at` | The time the account was created |
  246. | `followers_count` | The number of followers for the account |
  247. | `following_count` | The number of accounts the given account is following |
  248. | `statuses_count` | The number of statuses the account has made |
  249. ### Application
  250. | Attribute | Description |
  251. | ------------------------ | ----------- |
  252. | `name` | Name of the app |
  253. | `website` | Homepage URL of the app |
  254. ### Attachment
  255. | Attribute | Description |
  256. | ------------------------ | ----------- |
  257. | `id` | ID of the attachment |
  258. | `type` | One of: "image", "video", "gifv" |
  259. | `url` | URL of the locally hosted version of the image |
  260. | `remote_url` | For remote images, the remote URL of the original image |
  261. | `preview_url` | URL of the preview image |
  262. | `text_url` | Shorter URL for the image, for insertion into text (only present on local images) |
  263. ### Card
  264. | Attribute | Description |
  265. | ------------------------ | ----------- |
  266. | `url` | The url associated with the card |
  267. | `title` | The title of the card |
  268. | `description` | The card description |
  269. | `image` | The image associated with the card, if any |
  270. ### Context
  271. | Attribute | Description |
  272. | ------------------------ | ----------- |
  273. | `ancestors` | The ancestors of the status in the conversation, as a list of [Statuses](#status) |
  274. | `descendants` | The descendants of the status in the conversation, as a list of [Statuses](#status) |
  275. ### Error
  276. | Attribute | Description |
  277. | ------------------------ | ----------- |
  278. | `error` | A textual description of the error |
  279. ### Instance
  280. | Attribute | Description |
  281. | ------------------------ | ----------- |
  282. | `uri` | URI of the current instance |
  283. | `title` | The instance's title |
  284. | `description` | A description for the instance |
  285. | `email` | An email address which can be used to contact the instance administrator |
  286. ### Mention
  287. | Attribute | Description |
  288. | ------------------------ | ----------- |
  289. | `url` | URL of user's profile (can be remote) |
  290. | `username` | The username of the account |
  291. | `acct` | Equals `username` for local users, includes `@domain` for remote ones |
  292. | `id` | Account ID |
  293. ### Notification
  294. | Attribute | Description |
  295. | ------------------------ | ----------- |
  296. | `id` | The notification ID |
  297. | `type` | One of: "mention", "reblog", "favourite", "follow" |
  298. | `created_at` | The time the notification was created |
  299. | `account` | The [Account](#account) sending the notification to the user |
  300. | `status` | The [Status](#status) associated with the notification, if applicable |
  301. ### Relationship
  302. | Attribute | Description |
  303. | ------------------------ | ----------- |
  304. | `following` | Whether the user is currently following the account |
  305. | `followed_by` | Whether the user is currently being followed by the account |
  306. | `blocking` | Whether the user is currently blocking the account |
  307. | `muting` | Whether the user is currently muting the account |
  308. | `requested` | Whether the user has requested to follow the account |
  309. ### Report
  310. | Attribute | Description |
  311. | ------------------------ | ----------- |
  312. | `id` | The ID of the report |
  313. | `action_taken` | The action taken in response to the report |
  314. ### Results
  315. | Attribute | Description |
  316. | ------------------------ | ----------- |
  317. | `accounts` | An array of matched [Accounts](#account) |
  318. | `statuses` | An array of matchhed [Statuses](#status) |
  319. | `hashtags` | An array of matched hashtags, as strings |
  320. ### Status
  321. | Attribute | Description |
  322. | ------------------------ | ----------- |
  323. | `id` | The ID of the status |
  324. | `uri` | A Fediverse-unique resource ID |
  325. | `url` | URL to the status page (can be remote) |
  326. | `account` | The [Account](#account) which posted the status |
  327. | `in_reply_to_id` | `null` or the ID of the status it replies to |
  328. | `in_reply_to_account_id` | `null` or the ID of the account it replies to |
  329. | `reblog` | `null` or the reblogged [Status](#status) |
  330. | `content` | Body of the status; this will contain HTML (remote HTML already sanitized) |
  331. | `created_at` | The time the status was created |
  332. | `reblogs_count` | The number of reblogs for the status |
  333. | `favourites_count` | The number of favourites for the status |
  334. | `reblogged` | Whether the authenticated user has reblogged the status |
  335. | `favourited` | Whether the authenticated user has favourited the status |
  336. | `sensitive` | Whether media attachments should be hidden by default |
  337. | `spoiler_text` | If not empty, warning text that should be displayed before the actual content |
  338. | `visibility` | One of: `public`, `unlisted`, `private`, `direct` |
  339. | `media_attachments` | An array of [Attachments](#attachment) |
  340. | `mentions` | An array of [Mentions](#mention) |
  341. | `tags` | An array of [Tags](#tag) |
  342. | `application` | [Application](#application) from which the status was posted |
  343. ### Tag
  344. | Attribute | Description |
  345. | ------------------------ | ----------- |
  346. | `name` | The hashtag, not including the preceding `#` |
  347. | `url` | The URL of the hashtag |