1
0

user_admin_api.rst 13 KB

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