闭社主体 forked from https://github.com/tootsuite/mastodon
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.

524 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
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. - [Relationships](#relationships)
  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. #### Getting an account's followers:
  65. GET /api/v1/accounts/:id/followers
  66. Returns an array of [Accounts](#account).
  67. #### Getting who account is following:
  68. GET /api/v1/accounts/:id/following
  69. Returns an array of [Accounts](#account).
  70. #### Getting an account's statuses:
  71. GET /api/v1/accounts/:id/statuses
  72. Query parameters:
  73. - `only_media` (optional): Only return statuses that have media attachments
  74. - `exclude_replies` (optional): Skip statuses that reply to other statuses
  75. Returns an array of [Statuses](#status).
  76. #### Following/unfollowing an account:
  77. GET /api/v1/accounts/:id/follow
  78. GET /api/v1/accounts/:id/unfollow
  79. Returns the target [Account](#account).
  80. #### Blocking/unblocking an account:
  81. GET /api/v1/accounts/:id/block
  82. GET /api/v1/accounts/:id/unblock
  83. Returns the target [Account](#account).
  84. #### Muting/unmuting an account:
  85. GET /api/v1/accounts/:id/mute
  86. GET /api/v1/accounts/:id/unmute
  87. Returns the target [Account](#account).
  88. #### Getting an account's relationships:
  89. GET /api/v1/accounts/relationships
  90. Query parameters:
  91. - `id` (can be array): Account IDs
  92. Returns an array of [Relationships](#relationships) of the current user to a list of given accounts.
  93. #### Searching for accounts:
  94. GET /api/v1/accounts/search
  95. Query parameters:
  96. - `q`: What to search for
  97. - `limit`: Maximum number of matching accounts to return (default: `40`)
  98. Returns an array of matching [Accounts](#accounts).
  99. Will lookup an account remotely if the search term is in the `username@domain` format and not yet in the database.
  100. ### Apps
  101. #### Registering an application:
  102. POST /api/v1/apps
  103. Form data:
  104. - `client_name`: Name of your application
  105. - `redirect_uris`: Where the user should be redirected after authorization (for no redirect, use `urn:ietf:wg:oauth:2.0:oob`)
  106. - `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)
  107. - `website`: (optional) URL to the homepage of your app
  108. Creates a new OAuth app.
  109. Returns `id`, `client_id` and `client_secret` which can be used with [OAuth authentication in your 3rd party app](Testing-with-cURL.md).
  110. 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.
  111. ### Blocks
  112. #### Fetching a user's blocks:
  113. GET /api/v1/blocks
  114. Returns an array of [Accounts](#account) blocked by the authenticated user.
  115. ### Favourites
  116. #### Fetching a user's favourites:
  117. GET /api/v1/favourites
  118. Returns an array of [Statuses](#status) favourited by the authenticated user.
  119. ### Follow Requests
  120. #### Fetching a list of follow requests:
  121. GET /api/v1/follow_requests
  122. Returns an array of [Accounts](#account) which have requested to follow the authenticated user.
  123. #### Authorizing or rejecting follow requests:
  124. POST /api/v1/follow_requests/authorize
  125. POST /api/v1/follow_requests/reject
  126. Form data:
  127. - `id`: The id of the account to authorize or reject
  128. Returns an empty object.
  129. ### Follows
  130. #### Following a remote user:
  131. POST /api/v1/follows
  132. Form data:
  133. - `uri`: `username@domain` of the person you want to follow
  134. Returns the local representation of the followed account, as an [Account](#account).
  135. ### Instances
  136. #### Getting instance information:
  137. GET /api/v1/instance
  138. Returns the current [Instance](#instance).
  139. Does not require authentication.
  140. ### Media
  141. #### Uploading a media attachment:
  142. POST /api/v1/media
  143. Form data:
  144. - `file`: Media to be uploaded
  145. Returns an [Attachment](#attachment) that can be used when creating a status.
  146. ### Mutes
  147. #### Fetching a user's mutes:
  148. GET /api/v1/mutes
  149. Returns an array of [Accounts](#account) muted by the authenticated user.
  150. ### Notifications
  151. #### Fetching a user's notifications:
  152. GET /api/v1/notifications
  153. Returns a list of [Notifications](#notification) for the authenticated user.
  154. #### Getting a single notification:
  155. GET /api/v1/notifications/:id
  156. Returns the [Notification](#notification).
  157. #### Clearing notifications:
  158. POST /api/v1/notifications/clear
  159. Deletes all notifications from the Mastodon server for the authenticated user.
  160. Returns an empty object.
  161. ### Reports
  162. #### Fetching a user's reports:
  163. GET /api/v1/reports
  164. Returns a list of [Reports](#report) made by the authenticated user.
  165. #### Reporting a user:
  166. POST /api/v1/reports
  167. Form data:
  168. - `account_id`: The ID of the account to report
  169. - `status_ids`: The IDs of statuses to report (can be an array)
  170. - `comment`: A comment to associate with the report.
  171. Returns the finished [Report](#report).
  172. ### Search
  173. #### Searching for content:
  174. GET /api/v1/search
  175. Form data:
  176. - `q`: The search query
  177. - `resolve`: Whether to resolve non-local accounts
  178. Returns [Results](#results).
  179. If `q` is a URL, Mastodon will attempt to fetch the provided account or status.
  180. Otherwise, it will do a local account and hashtag search.
  181. ### Statuses
  182. #### Fetching a status:
  183. GET /api/v1/statuses/:id
  184. Returns a [Status](#status).
  185. #### Getting status context:
  186. GET /api/v1/statuses/:id/context
  187. Returns a [Context](#context).
  188. #### Getting a card associated with a status:
  189. GET /api/v1/statuses/:id/card
  190. Returns a [Card](#card).
  191. #### Getting who reblogged/favourited a status:
  192. GET /api/v1/statuses/:id/reblogged_by
  193. GET /api/v1/statuses/:id/favourited_by
  194. Returns an array of [Accounts](#account).
  195. #### Posting a new status:
  196. POST /api/v1/statuses
  197. Form data:
  198. - `status`: The text of the status
  199. - `in_reply_to_id` (optional): local ID of the status you want to reply to
  200. - `media_ids` (optional): array of media IDs to attach to the status (maximum 4)
  201. - `sensitive` (optional): set this to mark the media of the status as NSFW
  202. - `spoiler_text` (optional): text to be shown as a warning before the actual content
  203. - `visibility` (optional): either "direct", "private", "unlisted" or "public"
  204. Returns the new [Status](#status).
  205. #### Deleting a status:
  206. DELETE /api/v1/statuses/:id
  207. Returns an empty object.
  208. #### Reblogging/unreblogging a status:
  209. POST /api/vi/statuses/:id/reblog
  210. POST /api/vi/statuses/:id/unreblog
  211. Returns the target [Status](#status).
  212. #### Favouriting/unfavouriting a status:
  213. POST /api/vi/statuses/:id/favourite
  214. POST /api/vi/statuses/:id/unfavourite
  215. Returns the target [Status](#status).
  216. ### Timelines
  217. #### Retrieving a timeline:
  218. GET /api/v1/timelines/home
  219. GET /api/v1/timelines/public
  220. GET /api/v1/timelines/tag/:hashtag
  221. Query parameters:
  222. - `local` (optional; public and tag timelines only): Only return statuses originating from this instance
  223. Returns an array of [Statuses](#status), most recent ones first.
  224. ___
  225. ## Entities
  226. ### Account
  227. | Attribute | Description |
  228. | ------------------------ | ----------- |
  229. | `id` | The ID of the account |
  230. | `username` | The username of the account |
  231. | `acct` | Equals `username` for local users, includes `@domain` for remote ones |
  232. | `display_name` | The account's display name |
  233. | `note` | Biography of user |
  234. | `url` | URL of the user's profile page (can be remote) |
  235. | `avatar` | URL to the avatar image |
  236. | `header` | URL to the header image |
  237. | `locked` | Boolean for when the account cannot be followed without waiting for approval first |
  238. | `created_at` | The time the account was created |
  239. | `followers_count` | The number of followers for the account |
  240. | `following_count` | The number of accounts the given account is following |
  241. | `statuses_count` | The number of statuses the account has made |
  242. ### Application
  243. | Attribute | Description |
  244. | ------------------------ | ----------- |
  245. | `name` | Name of the app |
  246. | `website` | Homepage URL of the app |
  247. ### Attachment
  248. | Attribute | Description |
  249. | ------------------------ | ----------- |
  250. | `id` | ID of the attachment |
  251. | `type` | One of: "image", "video", "gifv" |
  252. | `url` | URL of the locally hosted version of the image |
  253. | `remote_url` | For remote images, the remote URL of the original image |
  254. | `preview_url` | URL of the preview image |
  255. | `text_url` | Shorter URL for the image, for insertion into text (only present on local images) |
  256. ### Card
  257. | Attribute | Description |
  258. | ------------------------ | ----------- |
  259. | `url` | The url associated with the card |
  260. | `title` | The title of the card |
  261. | `description` | The card description |
  262. | `image` | The image associated with the card, if any |
  263. ### Context
  264. | Attribute | Description |
  265. | ------------------------ | ----------- |
  266. | `ancestors` | The ancestors of the status in the conversation, as a list of [Statuses](#status) |
  267. | `descendants` | The descendants of the status in the conversation, as a list of [Statuses](#status) |
  268. ### Error
  269. | Attribute | Description |
  270. | ------------------------ | ----------- |
  271. | `error` | A textual description of the error |
  272. ### Instance
  273. | Attribute | Description |
  274. | ------------------------ | ----------- |
  275. | `uri` | URI of the current instance |
  276. | `title` | The instance's title |
  277. | `description` | A description for the instance |
  278. | `email` | An email address which can be used to contact the instance administrator |
  279. ### Mention
  280. | Attribute | Description |
  281. | ------------------------ | ----------- |
  282. | `url` | URL of user's profile (can be remote) |
  283. | `username` | The username of the account |
  284. | `acct` | Equals `username` for local users, includes `@domain` for remote ones |
  285. | `id` | Account ID |
  286. ### Notifications
  287. | Attribute | Description |
  288. | ------------------------ | ----------- |
  289. | `id` | The notification ID |
  290. | `type` | One of: "mention", "reblog", "favourite", "follow" |
  291. | `created_at` | The time the notification was created |
  292. | `account` | The [Account](#account) sending the notification to the user |
  293. | `status` | The [Status](#status) associated with the notification, if applicible |
  294. ### Relationships
  295. | Attribute | Description |
  296. | ------------------------ | ----------- |
  297. | `following` | Whether the user is currently following the account |
  298. | `followed_by` | Whether the user is currently being followed by the account |
  299. | `blocking` | Whether the user is currently blocking the account |
  300. | `muting` | Whether the user is currently muting the account |
  301. | `requested` | Whether the user has requested to follow the account |
  302. ### Report
  303. | Attribute | Description |
  304. | ------------------------ | ----------- |
  305. | `id` | The ID of the report |
  306. | `action_taken` | The action taken in response to the report |
  307. ### Results
  308. | Attribute | Description |
  309. | ------------------------ | ----------- |
  310. | `accounts` | An array of matched [Accounts](#account) |
  311. | `statuses` | An array of matchhed [Statuses](#status) |
  312. | `hashtags` | An array of matched hashtags, as strings |
  313. ### Status
  314. | Attribute | Description |
  315. | ------------------------ | ----------- |
  316. | `id` | The ID of the status |
  317. | `uri` | A Fediverse-unique resource ID |
  318. | `url` | URL to the status page (can be remote) |
  319. | `account` | The [Account](#account) which posted the status |
  320. | `in_reply_to_id` | `null` or the ID of the status it replies to |
  321. | `in_reply_to_account_id` | `null` or the ID of the account it replies to |
  322. | `reblog` | `null` or the reblogged [Status](#status) |
  323. | `content` | Body of the status; this will contain HTML (remote HTML already sanitized) |
  324. | `created_at` | The time the status was created |
  325. | `reblogs_count` | The number of reblogs for the status |
  326. | `favourites_count` | The number of favourites for the status |
  327. | `reblogged` | Whether the authenticated user has reblogged the status |
  328. | `favourited` | Whether the authenticated user has favourited the status |
  329. | `sensitive` | Whether media attachments should be hidden by default |
  330. | `spoiler_text` | If not empty, warning text that should be displayed before the actual content |
  331. | `visibility` | One of: `public`, `unlisted`, `private`, `direct` |
  332. | `media_attachments` | An array of [Attachments](#attachment) |
  333. | `mentions` | An array of [Mentions](#mention) |
  334. | `tags` | An array of [Tags](#tag) |
  335. | `application` | [Application](#application) from which the status was posted |
  336. ### Tags
  337. | Attribute | Description |
  338. | ------------------------ | ----------- |
  339. | `name` | The hashtag, not including the preceding `#` |
  340. | `url` | The URL of the hashtag |