user_admin_api.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. .. contents::
  2. Query User Account
  3. ==================
  4. This API returns information about a specific user account.
  5. The api is::
  6. GET /_synapse/admin/v2/users/<user_id>
  7. To use it, you will need to authenticate by providing an ``access_token`` for a
  8. server admin: see `README.rst <README.rst>`_.
  9. It returns a JSON body like the following:
  10. .. code:: json
  11. {
  12. "displayname": "User",
  13. "threepids": [
  14. {
  15. "medium": "email",
  16. "address": "<user_mail_1>"
  17. },
  18. {
  19. "medium": "email",
  20. "address": "<user_mail_2>"
  21. }
  22. ],
  23. "avatar_url": "<avatar_url>",
  24. "admin": false,
  25. "deactivated": false
  26. }
  27. URL parameters:
  28. - ``user_id``: fully-qualified user id: for example, ``@user:server.com``.
  29. Create or modify Account
  30. ========================
  31. This API allows an administrator to create or modify a user account with a
  32. specific ``user_id``.
  33. This api is::
  34. PUT /_synapse/admin/v2/users/<user_id>
  35. with a body of:
  36. .. code:: json
  37. {
  38. "password": "user_password",
  39. "displayname": "User",
  40. "threepids": [
  41. {
  42. "medium": "email",
  43. "address": "<user_mail_1>"
  44. },
  45. {
  46. "medium": "email",
  47. "address": "<user_mail_2>"
  48. }
  49. ],
  50. "avatar_url": "<avatar_url>",
  51. "admin": false,
  52. "deactivated": false
  53. }
  54. To use it, you will need to authenticate by providing an ``access_token`` for a
  55. server admin: see `README.rst <README.rst>`_.
  56. URL parameters:
  57. - ``user_id``: fully-qualified user id: for example, ``@user:server.com``.
  58. Body parameters:
  59. - ``password``, optional. If provided, the user's password is updated and all
  60. devices are logged out.
  61. - ``displayname``, optional, defaults to the value of ``user_id``.
  62. - ``threepids``, optional, allows setting the third-party IDs (email, msisdn)
  63. belonging to a user.
  64. - ``avatar_url``, optional, must be a
  65. `MXC URI <https://matrix.org/docs/spec/client_server/r0.6.0#matrix-content-mxc-uris>`_.
  66. - ``admin``, optional, defaults to ``false``.
  67. - ``deactivated``, optional, defaults to ``false``.
  68. If the user already exists then optional parameters default to the current value.
  69. List Accounts
  70. =============
  71. This API returns all local user accounts.
  72. The api is::
  73. GET /_synapse/admin/v2/users?from=0&limit=10&guests=false
  74. To use it, you will need to authenticate by providing an `access_token` for a
  75. server admin: see `README.rst <README.rst>`_.
  76. The parameter ``from`` is optional but used for pagination, denoting the
  77. offset in the returned results. This should be treated as an opaque value and
  78. not explicitly set to anything other than the return value of ``next_token``
  79. from a previous call.
  80. The parameter ``limit`` is optional but is used for pagination, denoting the
  81. maximum number of items to return in this call. Defaults to ``100``.
  82. The parameter ``user_id`` is optional and filters to only users with user IDs
  83. that contain this value.
  84. The parameter ``guests`` is optional and if ``false`` will **exclude** guest users.
  85. Defaults to ``true`` to include guest users.
  86. The parameter ``deactivated`` is optional and if ``true`` will **include** deactivated users.
  87. Defaults to ``false`` to exclude deactivated users.
  88. A JSON body is returned with the following shape:
  89. .. code:: json
  90. {
  91. "users": [
  92. {
  93. "name": "<user_id1>",
  94. "password_hash": "<password_hash1>",
  95. "is_guest": 0,
  96. "admin": 0,
  97. "user_type": null,
  98. "deactivated": 0,
  99. "displayname": "<User One>",
  100. "avatar_url": null
  101. }, {
  102. "name": "<user_id2>",
  103. "password_hash": "<password_hash2>",
  104. "is_guest": 0,
  105. "admin": 1,
  106. "user_type": null,
  107. "deactivated": 0,
  108. "displayname": "<User Two>",
  109. "avatar_url": "<avatar_url>"
  110. }
  111. ],
  112. "next_token": "100",
  113. "total": 200
  114. }
  115. To paginate, check for ``next_token`` and if present, call the endpoint again
  116. with ``from`` set to the value of ``next_token``. This will return a new page.
  117. If the endpoint does not return a ``next_token`` then there are no more users
  118. to paginate through.
  119. Query current sessions for a user
  120. =================================
  121. This API returns information about the active sessions for a specific user.
  122. The api is::
  123. GET /_synapse/admin/v1/whois/<user_id>
  124. To use it, you will need to authenticate by providing an ``access_token`` for a
  125. server admin: see `README.rst <README.rst>`_.
  126. It returns a JSON body like the following:
  127. .. code:: json
  128. {
  129. "user_id": "<user_id>",
  130. "devices": {
  131. "": {
  132. "sessions": [
  133. {
  134. "connections": [
  135. {
  136. "ip": "1.2.3.4",
  137. "last_seen": 1417222374433,
  138. "user_agent": "Mozilla/5.0 ..."
  139. },
  140. {
  141. "ip": "1.2.3.10",
  142. "last_seen": 1417222374500,
  143. "user_agent": "Dalvik/2.1.0 ..."
  144. }
  145. ]
  146. }
  147. ]
  148. }
  149. }
  150. }
  151. ``last_seen`` is measured in milliseconds since the Unix epoch.
  152. Deactivate Account
  153. ==================
  154. This API deactivates an account. It removes active access tokens, resets the
  155. password, and deletes third-party IDs (to prevent the user requesting a
  156. password reset). It can also mark the user as GDPR-erased (stopping their data
  157. from distributed further, and deleting it entirely if there are no other
  158. references to it).
  159. The api is::
  160. POST /_synapse/admin/v1/deactivate/<user_id>
  161. with a body of:
  162. .. code:: json
  163. {
  164. "erase": true
  165. }
  166. To use it, you will need to authenticate by providing an ``access_token`` for a
  167. server admin: see `README.rst <README.rst>`_.
  168. The erase parameter is optional and defaults to ``false``.
  169. An empty body may be passed for backwards compatibility.
  170. Reset password
  171. ==============
  172. Changes the password of another user. This will automatically log the user out of all their devices.
  173. The api is::
  174. POST /_synapse/admin/v1/reset_password/<user_id>
  175. with a body of:
  176. .. code:: json
  177. {
  178. "new_password": "<secret>",
  179. "logout_devices": true,
  180. }
  181. To use it, you will need to authenticate by providing an ``access_token`` for a
  182. server admin: see `README.rst <README.rst>`_.
  183. The parameter ``new_password`` is required.
  184. The parameter ``logout_devices`` is optional and defaults to ``true``.
  185. Get whether a user is a server administrator or not
  186. ===================================================
  187. The api is::
  188. GET /_synapse/admin/v1/users/<user_id>/admin
  189. To use it, you will need to authenticate by providing an ``access_token`` for a
  190. server admin: see `README.rst <README.rst>`_.
  191. A response body like the following is returned:
  192. .. code:: json
  193. {
  194. "admin": true
  195. }
  196. Change whether a user is a server administrator or not
  197. ======================================================
  198. Note that you cannot demote yourself.
  199. The api is::
  200. PUT /_synapse/admin/v1/users/<user_id>/admin
  201. with a body of:
  202. .. code:: json
  203. {
  204. "admin": true
  205. }
  206. To use it, you will need to authenticate by providing an ``access_token`` for a
  207. server admin: see `README.rst <README.rst>`_.
  208. User devices
  209. ============
  210. List all devices
  211. ----------------
  212. Gets information about all devices for a specific ``user_id``.
  213. The API is::
  214. GET /_synapse/admin/v2/users/<user_id>/devices
  215. To use it, you will need to authenticate by providing an ``access_token`` for a
  216. server admin: see `README.rst <README.rst>`_.
  217. A response body like the following is returned:
  218. .. code:: json
  219. {
  220. "devices": [
  221. {
  222. "device_id": "QBUAZIFURK",
  223. "display_name": "android",
  224. "last_seen_ip": "1.2.3.4",
  225. "last_seen_ts": 1474491775024,
  226. "user_id": "<user_id>"
  227. },
  228. {
  229. "device_id": "AUIECTSRND",
  230. "display_name": "ios",
  231. "last_seen_ip": "1.2.3.5",
  232. "last_seen_ts": 1474491775025,
  233. "user_id": "<user_id>"
  234. }
  235. ]
  236. }
  237. **Parameters**
  238. The following parameters should be set in the URL:
  239. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  240. **Response**
  241. The following fields are returned in the JSON response body:
  242. - ``devices`` - An array of objects, each containing information about a device.
  243. Device objects contain the following fields:
  244. - ``device_id`` - Identifier of device.
  245. - ``display_name`` - Display name set by the user for this device.
  246. Absent if no name has been set.
  247. - ``last_seen_ip`` - The IP address where this device was last seen.
  248. (May be a few minutes out of date, for efficiency reasons).
  249. - ``last_seen_ts`` - The timestamp (in milliseconds since the unix epoch) when this
  250. devices was last seen. (May be a few minutes out of date, for efficiency reasons).
  251. - ``user_id`` - Owner of device.
  252. Delete multiple devices
  253. ------------------
  254. Deletes the given devices for a specific ``user_id``, and invalidates
  255. any access token associated with them.
  256. The API is::
  257. POST /_synapse/admin/v2/users/<user_id>/delete_devices
  258. {
  259. "devices": [
  260. "QBUAZIFURK",
  261. "AUIECTSRND"
  262. ],
  263. }
  264. To use it, you will need to authenticate by providing an ``access_token`` for a
  265. server admin: see `README.rst <README.rst>`_.
  266. An empty JSON dict is returned.
  267. **Parameters**
  268. The following parameters should be set in the URL:
  269. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  270. The following fields are required in the JSON request body:
  271. - ``devices`` - The list of device IDs to delete.
  272. Show a device
  273. ---------------
  274. Gets information on a single device, by ``device_id`` for a specific ``user_id``.
  275. The API is::
  276. GET /_synapse/admin/v2/users/<user_id>/devices/<device_id>
  277. To use it, you will need to authenticate by providing an ``access_token`` for a
  278. server admin: see `README.rst <README.rst>`_.
  279. A response body like the following is returned:
  280. .. code:: json
  281. {
  282. "device_id": "<device_id>",
  283. "display_name": "android",
  284. "last_seen_ip": "1.2.3.4",
  285. "last_seen_ts": 1474491775024,
  286. "user_id": "<user_id>"
  287. }
  288. **Parameters**
  289. The following parameters should be set in the URL:
  290. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  291. - ``device_id`` - The device to retrieve.
  292. **Response**
  293. The following fields are returned in the JSON response body:
  294. - ``device_id`` - Identifier of device.
  295. - ``display_name`` - Display name set by the user for this device.
  296. Absent if no name has been set.
  297. - ``last_seen_ip`` - The IP address where this device was last seen.
  298. (May be a few minutes out of date, for efficiency reasons).
  299. - ``last_seen_ts`` - The timestamp (in milliseconds since the unix epoch) when this
  300. devices was last seen. (May be a few minutes out of date, for efficiency reasons).
  301. - ``user_id`` - Owner of device.
  302. Update a device
  303. ---------------
  304. Updates the metadata on the given ``device_id`` for a specific ``user_id``.
  305. The API is::
  306. PUT /_synapse/admin/v2/users/<user_id>/devices/<device_id>
  307. {
  308. "display_name": "My other phone"
  309. }
  310. To use it, you will need to authenticate by providing an ``access_token`` for a
  311. server admin: see `README.rst <README.rst>`_.
  312. An empty JSON dict is returned.
  313. **Parameters**
  314. The following parameters should be set in the URL:
  315. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  316. - ``device_id`` - The device to update.
  317. The following fields are required in the JSON request body:
  318. - ``display_name`` - The new display name for this device. If not given,
  319. the display name is unchanged.
  320. Delete a device
  321. ---------------
  322. Deletes the given ``device_id`` for a specific ``user_id``,
  323. and invalidates any access token associated with it.
  324. The API is::
  325. DELETE /_synapse/admin/v2/users/<user_id>/devices/<device_id>
  326. {}
  327. To use it, you will need to authenticate by providing an ``access_token`` for a
  328. server admin: see `README.rst <README.rst>`_.
  329. An empty JSON dict is returned.
  330. **Parameters**
  331. The following parameters should be set in the URL:
  332. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  333. - ``device_id`` - The device to delete.