user_admin_api.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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 return users with user IDs
  86. that contain this value. This parameter is ignored when using the ``name`` parameter.
  87. The parameter ``name`` is optional and filters to only return users with user ID localparts
  88. **or** displaynames that contain this value.
  89. The parameter ``guests`` is optional and if ``false`` will **exclude** guest users.
  90. Defaults to ``true`` to include guest users.
  91. The parameter ``deactivated`` is optional and if ``true`` will **include** deactivated users.
  92. Defaults to ``false`` to exclude deactivated users.
  93. A JSON body is returned with the following shape:
  94. .. code:: json
  95. {
  96. "users": [
  97. {
  98. "name": "<user_id1>",
  99. "password_hash": "<password_hash1>",
  100. "is_guest": 0,
  101. "admin": 0,
  102. "user_type": null,
  103. "deactivated": 0,
  104. "displayname": "<User One>",
  105. "avatar_url": null
  106. }, {
  107. "name": "<user_id2>",
  108. "password_hash": "<password_hash2>",
  109. "is_guest": 0,
  110. "admin": 1,
  111. "user_type": null,
  112. "deactivated": 0,
  113. "displayname": "<User Two>",
  114. "avatar_url": "<avatar_url>"
  115. }
  116. ],
  117. "next_token": "100",
  118. "total": 200
  119. }
  120. To paginate, check for ``next_token`` and if present, call the endpoint again
  121. with ``from`` set to the value of ``next_token``. This will return a new page.
  122. If the endpoint does not return a ``next_token`` then there are no more users
  123. to paginate through.
  124. Query current sessions for a user
  125. =================================
  126. This API returns information about the active sessions for a specific user.
  127. The api is::
  128. GET /_synapse/admin/v1/whois/<user_id>
  129. and::
  130. GET /_matrix/client/r0/admin/whois/<userId>
  131. See also: `Client Server API Whois
  132. <https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid>`_
  133. To use it, you will need to authenticate by providing an ``access_token`` for a
  134. server admin: see `README.rst <README.rst>`_.
  135. It returns a JSON body like the following:
  136. .. code:: json
  137. {
  138. "user_id": "<user_id>",
  139. "devices": {
  140. "": {
  141. "sessions": [
  142. {
  143. "connections": [
  144. {
  145. "ip": "1.2.3.4",
  146. "last_seen": 1417222374433,
  147. "user_agent": "Mozilla/5.0 ..."
  148. },
  149. {
  150. "ip": "1.2.3.10",
  151. "last_seen": 1417222374500,
  152. "user_agent": "Dalvik/2.1.0 ..."
  153. }
  154. ]
  155. }
  156. ]
  157. }
  158. }
  159. }
  160. ``last_seen`` is measured in milliseconds since the Unix epoch.
  161. Deactivate Account
  162. ==================
  163. This API deactivates an account. It removes active access tokens, resets the
  164. password, and deletes third-party IDs (to prevent the user requesting a
  165. password reset).
  166. It can also mark the user as GDPR-erased. This means messages sent by the
  167. user will still be visible by anyone that was in the room when these messages
  168. were sent, but hidden from users joining the room afterwards.
  169. The api is::
  170. POST /_synapse/admin/v1/deactivate/<user_id>
  171. with a body of:
  172. .. code:: json
  173. {
  174. "erase": true
  175. }
  176. To use it, you will need to authenticate by providing an ``access_token`` for a
  177. server admin: see `README.rst <README.rst>`_.
  178. The erase parameter is optional and defaults to ``false``.
  179. An empty body may be passed for backwards compatibility.
  180. Reset password
  181. ==============
  182. Changes the password of another user. This will automatically log the user out of all their devices.
  183. The api is::
  184. POST /_synapse/admin/v1/reset_password/<user_id>
  185. with a body of:
  186. .. code:: json
  187. {
  188. "new_password": "<secret>",
  189. "logout_devices": true
  190. }
  191. To use it, you will need to authenticate by providing an ``access_token`` for a
  192. server admin: see `README.rst <README.rst>`_.
  193. The parameter ``new_password`` is required.
  194. The parameter ``logout_devices`` is optional and defaults to ``true``.
  195. Get whether a user is a server administrator or not
  196. ===================================================
  197. The api is::
  198. GET /_synapse/admin/v1/users/<user_id>/admin
  199. To use it, you will need to authenticate by providing an ``access_token`` for a
  200. server admin: see `README.rst <README.rst>`_.
  201. A response body like the following is returned:
  202. .. code:: json
  203. {
  204. "admin": true
  205. }
  206. Change whether a user is a server administrator or not
  207. ======================================================
  208. Note that you cannot demote yourself.
  209. The api is::
  210. PUT /_synapse/admin/v1/users/<user_id>/admin
  211. with a body of:
  212. .. code:: json
  213. {
  214. "admin": true
  215. }
  216. To use it, you will need to authenticate by providing an ``access_token`` for a
  217. server admin: see `README.rst <README.rst>`_.
  218. List room memberships of an user
  219. ================================
  220. Gets a list of all ``room_id`` that a specific ``user_id`` is member.
  221. The API is::
  222. GET /_synapse/admin/v1/users/<user_id>/joined_rooms
  223. To use it, you will need to authenticate by providing an ``access_token`` for a
  224. server admin: see `README.rst <README.rst>`_.
  225. A response body like the following is returned:
  226. .. code:: json
  227. {
  228. "joined_rooms": [
  229. "!DuGcnbhHGaSZQoNQR:matrix.org",
  230. "!ZtSaPCawyWtxfWiIy:matrix.org"
  231. ],
  232. "total": 2
  233. }
  234. **Parameters**
  235. The following parameters should be set in the URL:
  236. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  237. **Response**
  238. The following fields are returned in the JSON response body:
  239. - ``joined_rooms`` - An array of ``room_id``.
  240. - ``total`` - Number of rooms.
  241. List media of an user
  242. ================================
  243. Gets a list of all local media that a specific ``user_id`` has created.
  244. The response is ordered by creation date descending and media ID descending.
  245. The newest media is on top.
  246. The API is::
  247. GET /_synapse/admin/v1/users/<user_id>/media
  248. To use it, you will need to authenticate by providing an ``access_token`` for a
  249. server admin: see `README.rst <README.rst>`_.
  250. A response body like the following is returned:
  251. .. code:: json
  252. {
  253. "media": [
  254. {
  255. "created_ts": 100400,
  256. "last_access_ts": null,
  257. "media_id": "qXhyRzulkwLsNHTbpHreuEgo",
  258. "media_length": 67,
  259. "media_type": "image/png",
  260. "quarantined_by": null,
  261. "safe_from_quarantine": false,
  262. "upload_name": "test1.png"
  263. },
  264. {
  265. "created_ts": 200400,
  266. "last_access_ts": null,
  267. "media_id": "FHfiSnzoINDatrXHQIXBtahw",
  268. "media_length": 67,
  269. "media_type": "image/png",
  270. "quarantined_by": null,
  271. "safe_from_quarantine": false,
  272. "upload_name": "test2.png"
  273. }
  274. ],
  275. "next_token": 3,
  276. "total": 2
  277. }
  278. To paginate, check for ``next_token`` and if present, call the endpoint again
  279. with ``from`` set to the value of ``next_token``. This will return a new page.
  280. If the endpoint does not return a ``next_token`` then there are no more
  281. reports to paginate through.
  282. **Parameters**
  283. The following parameters should be set in the URL:
  284. - ``user_id`` - string - fully qualified: for example, ``@user:server.com``.
  285. - ``limit``: string representing a positive integer - Is optional but is used for pagination,
  286. denoting the maximum number of items to return in this call. Defaults to ``100``.
  287. - ``from``: string representing a positive integer - Is optional but used for pagination,
  288. denoting the offset in the returned results. This should be treated as an opaque value and
  289. not explicitly set to anything other than the return value of ``next_token`` from a previous call.
  290. Defaults to ``0``.
  291. **Response**
  292. The following fields are returned in the JSON response body:
  293. - ``media`` - An array of objects, each containing information about a media.
  294. Media objects contain the following fields:
  295. - ``created_ts`` - integer - Timestamp when the content was uploaded in ms.
  296. - ``last_access_ts`` - integer - Timestamp when the content was last accessed in ms.
  297. - ``media_id`` - string - The id used to refer to the media.
  298. - ``media_length`` - integer - Length of the media in bytes.
  299. - ``media_type`` - string - The MIME-type of the media.
  300. - ``quarantined_by`` - string - The user ID that initiated the quarantine request
  301. for this media.
  302. - ``safe_from_quarantine`` - bool - Status if this media is safe from quarantining.
  303. - ``upload_name`` - string - The name the media was uploaded with.
  304. - ``next_token``: integer - Indication for pagination. See above.
  305. - ``total`` - integer - Total number of media.
  306. Login as a user
  307. ===============
  308. Get an access token that can be used to authenticate as that user. Useful for
  309. when admins wish to do actions on behalf of a user.
  310. The API is::
  311. POST /_synapse/admin/v1/users/<user_id>/login
  312. {}
  313. An optional ``valid_until_ms`` field can be specified in the request body as an
  314. integer timestamp that specifies when the token should expire. By default tokens
  315. do not expire.
  316. A response body like the following is returned:
  317. .. code:: json
  318. {
  319. "access_token": "<opaque_access_token_string>"
  320. }
  321. This API does *not* generate a new device for the user, and so will not appear
  322. their ``/devices`` list, and in general the target user should not be able to
  323. tell they have been logged in as.
  324. To expire the token call the standard ``/logout`` API with the token.
  325. Note: The token will expire if the *admin* user calls ``/logout/all`` from any
  326. of their devices, but the token will *not* expire if the target user does the
  327. same.
  328. User devices
  329. ============
  330. List all devices
  331. ----------------
  332. Gets information about all devices for a specific ``user_id``.
  333. The API is::
  334. GET /_synapse/admin/v2/users/<user_id>/devices
  335. To use it, you will need to authenticate by providing an ``access_token`` for a
  336. server admin: see `README.rst <README.rst>`_.
  337. A response body like the following is returned:
  338. .. code:: json
  339. {
  340. "devices": [
  341. {
  342. "device_id": "QBUAZIFURK",
  343. "display_name": "android",
  344. "last_seen_ip": "1.2.3.4",
  345. "last_seen_ts": 1474491775024,
  346. "user_id": "<user_id>"
  347. },
  348. {
  349. "device_id": "AUIECTSRND",
  350. "display_name": "ios",
  351. "last_seen_ip": "1.2.3.5",
  352. "last_seen_ts": 1474491775025,
  353. "user_id": "<user_id>"
  354. }
  355. ],
  356. "total": 2
  357. }
  358. **Parameters**
  359. The following parameters should be set in the URL:
  360. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  361. **Response**
  362. The following fields are returned in the JSON response body:
  363. - ``devices`` - An array of objects, each containing information about a device.
  364. Device objects contain the following fields:
  365. - ``device_id`` - Identifier of device.
  366. - ``display_name`` - Display name set by the user for this device.
  367. Absent if no name has been set.
  368. - ``last_seen_ip`` - The IP address where this device was last seen.
  369. (May be a few minutes out of date, for efficiency reasons).
  370. - ``last_seen_ts`` - The timestamp (in milliseconds since the unix epoch) when this
  371. devices was last seen. (May be a few minutes out of date, for efficiency reasons).
  372. - ``user_id`` - Owner of device.
  373. - ``total`` - Total number of user's devices.
  374. Delete multiple devices
  375. ------------------
  376. Deletes the given devices for a specific ``user_id``, and invalidates
  377. any access token associated with them.
  378. The API is::
  379. POST /_synapse/admin/v2/users/<user_id>/delete_devices
  380. {
  381. "devices": [
  382. "QBUAZIFURK",
  383. "AUIECTSRND"
  384. ],
  385. }
  386. To use it, you will need to authenticate by providing an ``access_token`` for a
  387. server admin: see `README.rst <README.rst>`_.
  388. An empty JSON dict is returned.
  389. **Parameters**
  390. The following parameters should be set in the URL:
  391. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  392. The following fields are required in the JSON request body:
  393. - ``devices`` - The list of device IDs to delete.
  394. Show a device
  395. ---------------
  396. Gets information on a single device, by ``device_id`` for a specific ``user_id``.
  397. The API is::
  398. GET /_synapse/admin/v2/users/<user_id>/devices/<device_id>
  399. To use it, you will need to authenticate by providing an ``access_token`` for a
  400. server admin: see `README.rst <README.rst>`_.
  401. A response body like the following is returned:
  402. .. code:: json
  403. {
  404. "device_id": "<device_id>",
  405. "display_name": "android",
  406. "last_seen_ip": "1.2.3.4",
  407. "last_seen_ts": 1474491775024,
  408. "user_id": "<user_id>"
  409. }
  410. **Parameters**
  411. The following parameters should be set in the URL:
  412. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  413. - ``device_id`` - The device to retrieve.
  414. **Response**
  415. The following fields are returned in the JSON response body:
  416. - ``device_id`` - Identifier of device.
  417. - ``display_name`` - Display name set by the user for this device.
  418. Absent if no name has been set.
  419. - ``last_seen_ip`` - The IP address where this device was last seen.
  420. (May be a few minutes out of date, for efficiency reasons).
  421. - ``last_seen_ts`` - The timestamp (in milliseconds since the unix epoch) when this
  422. devices was last seen. (May be a few minutes out of date, for efficiency reasons).
  423. - ``user_id`` - Owner of device.
  424. Update a device
  425. ---------------
  426. Updates the metadata on the given ``device_id`` for a specific ``user_id``.
  427. The API is::
  428. PUT /_synapse/admin/v2/users/<user_id>/devices/<device_id>
  429. {
  430. "display_name": "My other phone"
  431. }
  432. To use it, you will need to authenticate by providing an ``access_token`` for a
  433. server admin: see `README.rst <README.rst>`_.
  434. An empty JSON dict is returned.
  435. **Parameters**
  436. The following parameters should be set in the URL:
  437. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  438. - ``device_id`` - The device to update.
  439. The following fields are required in the JSON request body:
  440. - ``display_name`` - The new display name for this device. If not given,
  441. the display name is unchanged.
  442. Delete a device
  443. ---------------
  444. Deletes the given ``device_id`` for a specific ``user_id``,
  445. and invalidates any access token associated with it.
  446. The API is::
  447. DELETE /_synapse/admin/v2/users/<user_id>/devices/<device_id>
  448. {}
  449. To use it, you will need to authenticate by providing an ``access_token`` for a
  450. server admin: see `README.rst <README.rst>`_.
  451. An empty JSON dict is returned.
  452. **Parameters**
  453. The following parameters should be set in the URL:
  454. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  455. - ``device_id`` - The device to delete.
  456. List all pushers
  457. ================
  458. Gets information about all pushers for a specific ``user_id``.
  459. The API is::
  460. GET /_synapse/admin/v1/users/<user_id>/pushers
  461. To use it, you will need to authenticate by providing an ``access_token`` for a
  462. server admin: see `README.rst <README.rst>`_.
  463. A response body like the following is returned:
  464. .. code:: json
  465. {
  466. "pushers": [
  467. {
  468. "app_display_name":"HTTP Push Notifications",
  469. "app_id":"m.http",
  470. "data": {
  471. "url":"example.com"
  472. },
  473. "device_display_name":"pushy push",
  474. "kind":"http",
  475. "lang":"None",
  476. "profile_tag":"",
  477. "pushkey":"a@example.com"
  478. }
  479. ],
  480. "total": 1
  481. }
  482. **Parameters**
  483. The following parameters should be set in the URL:
  484. - ``user_id`` - fully qualified: for example, ``@user:server.com``.
  485. **Response**
  486. The following fields are returned in the JSON response body:
  487. - ``pushers`` - An array containing the current pushers for the user
  488. - ``app_display_name`` - string - A string that will allow the user to identify
  489. what application owns this pusher.
  490. - ``app_id`` - string - This is a reverse-DNS style identifier for the application.
  491. Max length, 64 chars.
  492. - ``data`` - A dictionary of information for the pusher implementation itself.
  493. - ``url`` - string - Required if ``kind`` is ``http``. The URL to use to send
  494. notifications to.
  495. - ``format`` - string - The format to use when sending notifications to the
  496. Push Gateway.
  497. - ``device_display_name`` - string - A string that will allow the user to identify
  498. what device owns this pusher.
  499. - ``profile_tag`` - string - This string determines which set of device specific rules
  500. this pusher executes.
  501. - ``kind`` - string - The kind of pusher. "http" is a pusher that sends HTTP pokes.
  502. - ``lang`` - string - The preferred language for receiving notifications
  503. (e.g. 'en' or 'en-US')
  504. - ``profile_tag`` - string - This string determines which set of device specific rules
  505. this pusher executes.
  506. - ``pushkey`` - string - This is a unique identifier for this pusher.
  507. Max length, 512 bytes.
  508. - ``total`` - integer - Number of pushers.
  509. See also `Client-Server API Spec <https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers>`_