Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Clarifications to the admin api documentation #7647

Merged
merged 4 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7647.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarifications to the admin api documentation.
18 changes: 11 additions & 7 deletions docs/admin_api/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ Admin APIs
This directory includes documentation for the various synapse specific admin
APIs available.

Only users that are server admins can use these APIs. A user can be marked as a
server admin by updating the database directly, e.g.:
Authenticating as a server admin
--------------------------------

``UPDATE users SET admin = 1 WHERE name = '@foo:bar.com'``
Many of the API calls in the admin api will require an `access_token` for a
server admin. (Note that a server admin is distinct from a room admin.)

Restarting may be required for the changes to register.
A user can be marked as a server admin by updating the database directly, e.g.:

Using an admin access_token
###########################
```sql
UPDATE users SET admin = 1 WHERE name = '@foo:bar.com';
```
richvdh marked this conversation as resolved.
Show resolved Hide resolved

A new server admin user can also be created using the
`register_new_matrix_user` script.
richvdh marked this conversation as resolved.
Show resolved Hide resolved

Many of the API calls listed in the documentation here will require to include an admin `access_token`.
Finding your user's `access_token` is client-dependent, but will usually be shown in the client's settings.

Once you have your `access_token`, to include it in a request, the best option is to add the token to a request header:
Expand Down
4 changes: 2 additions & 2 deletions docs/admin_api/delete_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ This API lets a server admin delete a local group. Doing so will kick all
users out of the group so that their clients will correctly handle the group
being deleted.


The API is:

```
POST /_synapse/admin/v1/delete_group/<group_id>
```

including an `access_token` of a server admin.
To use it, you will need to authenticate by providing an `access_token` for a
server admin: see [README.rst](README.rst).
6 changes: 3 additions & 3 deletions docs/admin_api/media_admin_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ The API is:
```
GET /_synapse/admin/v1/room/<room_id>/media
```
including an `access_token` of a server admin.
To use it, you will need to authenticate by providing an `access_token` for a
server admin: see [README.rst](README.rst).

It returns a JSON body like the following:
The API returns a JSON body like the following:
```
{
"local": [
Expand Down Expand Up @@ -99,4 +100,3 @@ Response:
"num_quarantined": 10 # The number of media items successfully quarantined
}
```

9 changes: 6 additions & 3 deletions docs/admin_api/purge_history_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ The API is:

``POST /_synapse/admin/v1/purge_history/<room_id>[/<event_id>]``

including an ``access_token`` of a server admin.
To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

By default, events sent by local users are not deleted, as they may represent
the only copies of this content in existence. (Events sent by remote users are
Expand Down Expand Up @@ -54,8 +55,10 @@ It is possible to poll for updates on recent purges with a second API;

``GET /_synapse/admin/v1/purge_history_status/<purge_id>``

(again, with a suitable ``access_token``). This API returns a JSON body like
the following:
Again, you will need to authenticate by providing an ``access_token`` for a
server admin.

This API returns a JSON body like the following:

.. code:: json

Expand Down
7 changes: 5 additions & 2 deletions docs/admin_api/purge_remote_media.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ media.

The API is::

POST /_synapse/admin/v1/purge_media_cache?before_ts=<unix_timestamp_in_ms>&access_token=<access_token>
POST /_synapse/admin/v1/purge_media_cache?before_ts=<unix_timestamp_in_ms>

{}

Which will remove all cached media that was last accessed before
\... which will remove all cached media that was last accessed before
``<unix_timestamp_in_ms>``.

To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

If the user re-requests purged remote media, synapse will re-request the media
from the originating server.
3 changes: 2 additions & 1 deletion docs/admin_api/room_membership.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ POST /_synapse/admin/v1/join/<room_id_or_alias>
}
```

Including an `access_token` of a server admin.
To use it, you will need to authenticate by providing an `access_token` for a
server admin: see [README.rst](README.rst).

Response:

Expand Down
113 changes: 49 additions & 64 deletions docs/admin_api/user_admin_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ with a body of:
"deactivated": false
}

including an ``access_token`` of a server admin.
To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

Parameters:

- ``password``, optional. If provided, the user's password is updated and all
devices are logged out.

- ``displayname``, optional, defaults to the value of ``user_id``.

- ``threepids``, optional, allows setting the third-party IDs (email, msisdn)
belonging to a user.

- ``avatar_url``, optional, must be a
- ``avatar_url``, optional, must be a
`MXC URI <https://matrix.org/docs/spec/client_server/r0.6.0#matrix-content-mxc-uris>`_.

- ``admin``, optional, defaults to ``false``.
Expand All @@ -63,7 +64,8 @@ The api is::

GET /_synapse/admin/v2/users?from=0&limit=10&guests=false

including an ``access_token`` of a server admin.
To use it, you will need to authenticate by providing an `access_token` for a
server admin: see `README.rst <README.rst>`_.

The parameter ``from`` is optional but used for pagination, denoting the
offset in the returned results. This should be treated as an opaque value and
Expand Down Expand Up @@ -125,10 +127,10 @@ This API returns information about a specific user account.

The api is::

GET /_synapse/admin/v1/whois/<user_id> (deprecated)
GET /_synapse/admin/v2/users/<user_id>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is a mistake in the documentation.
GET /_synapse/admin/v1/whois/<user_id> lists informations about the connections and GET /_synapse/admin/v2/users/<user_id> about the user. This are different APIs.


including an ``access_token`` of a server admin.
To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

It returns a JSON body like the following:

Expand Down Expand Up @@ -181,9 +183,10 @@ with a body of:
"erase": true
}

including an ``access_token`` of a server admin.
To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

The erase parameter is optional and defaults to 'false'.
The erase parameter is optional and defaults to ``false``.
An empty body may be passed for backwards compatibility.


Expand All @@ -205,7 +208,8 @@ with a body of:
"logout_devices": true,
}

including an ``access_token`` of a server admin.
To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

The parameter ``new_password`` is required.
The parameter ``logout_devices`` is optional and defaults to ``true``.
Expand All @@ -218,7 +222,8 @@ The api is::

GET /_synapse/admin/v1/users/<user_id>/admin

including an ``access_token`` of a server admin.
To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

A response body like the following is returned:

Expand Down Expand Up @@ -246,7 +251,8 @@ with a body of:
"admin": true
}

including an ``access_token`` of a server admin.
To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.


User devices
Expand All @@ -256,17 +262,14 @@ List all devices
----------------
Gets information about all devices for a specific ``user_id``.

**Usage**

A standard request to query the devices of an user:
The API is::

::
GET /_synapse/admin/v2/users/<user_id>/devices

GET /_synapse/admin/v2/users/<user_id>/devices

{}
To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

Response:
A response body like the following is returned:

.. code:: json

Expand All @@ -291,11 +294,13 @@ Response:

**Parameters**

The following query parameters are available:
The following parameters should be set in the URL:

- ``user_id`` - fully qualified: for example, ``@user:server.com``.

The following fields are possible in the JSON response body:
**Response**

The following fields are returned in the JSON response body:

- ``devices`` - An array of objects, each containing information about a device.
Device objects contain the following fields:
Expand All @@ -314,11 +319,7 @@ Delete multiple devices
Deletes the given devices for a specific ``user_id``, and invalidates
any access token associated with them.

**Usage**

A standard request to delete devices:

::
The API is::

POST /_synapse/admin/v2/users/<user_id>/delete_devices

Expand All @@ -329,16 +330,14 @@ A standard request to delete devices:
],
}

To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

Response:

.. code:: json

{}
An empty JSON dict is returned.

**Parameters**

The following query parameters are available:
The following parameters should be set in the URL:

- ``user_id`` - fully qualified: for example, ``@user:server.com``.

Expand All @@ -350,18 +349,14 @@ Show a device
---------------
Gets information on a single device, by ``device_id`` for a specific ``user_id``.

**Usage**

A standard request to get a device:

::
The API is::

GET /_synapse/admin/v2/users/<user_id>/devices/<device_id>

{}

To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

Response:
A response body like the following is returned:

.. code:: json

Expand All @@ -375,12 +370,14 @@ Response:

**Parameters**

The following query parameters are available:
The following parameters should be set in the URL:

- ``user_id`` - fully qualified: for example, ``@user:server.com``.
- ``device_id`` - The device to retrieve.

The following fields are possible in the JSON response body:
**Response**

The following fields are returned in the JSON response body:

- ``device_id`` - Identifier of device.
- ``display_name`` - Display name set by the user for this device.
Expand All @@ -395,28 +392,22 @@ Update a device
---------------
Updates the metadata on the given ``device_id`` for a specific ``user_id``.

**Usage**

A standard request to update a device:

::
The API is::

PUT /_synapse/admin/v2/users/<user_id>/devices/<device_id>

{
"display_name": "My other phone"
}

To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

Response:

.. code:: json

{}
An empty JSON dict is returned.

**Parameters**

The following query parameters are available:
The following parameters should be set in the URL:

- ``user_id`` - fully qualified: for example, ``@user:server.com``.
- ``device_id`` - The device to update.
Expand All @@ -431,26 +422,20 @@ Delete a device
Deletes the given ``device_id`` for a specific ``user_id``,
and invalidates any access token associated with it.

**Usage**

A standard request for delete a device:

::
The API is::

DELETE /_synapse/admin/v2/users/<user_id>/devices/<device_id>

{}

To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see `README.rst <README.rst>`_.

Response:

.. code:: json

{}
An empty JSON dict is returned.

**Parameters**

The following query parameters are available:
The following parameters should be set in the URL:

- ``user_id`` - fully qualified: for example, ``@user:server.com``.
- ``device_id`` - The device to delete.