Skip to content
Snippets Groups Projects
user_admin_api.md 46.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • exists already.
    
    The API is:
    
    ```
    POST /_synapse/admin/v2/users/<user_id>/devices
    
    {
      "device_id": "QBUAZIFURK"
    }
    ```
    
    An empty JSON dict is returned.
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - fully qualified: for example, `@user:server.com`.
    
    The following fields are required in the JSON request body:
    
    - `device_id` - The device ID to create.
    
    
    ### Delete multiple devices
    Deletes the given devices for a specific `user_id`, and invalidates
    any access token associated with them.
    
    The API is:
    
    ```
    POST /_synapse/admin/v2/users/<user_id>/delete_devices
    
    {
      "devices": [
        "QBUAZIFURK",
        "AUIECTSRND"
    
    }
    ```
    
    An empty JSON dict is returned.
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - fully qualified: for example, `@user:server.com`.
    
    The following fields are required in the JSON request body:
    
    - `devices` - The list of device IDs to delete.
    
    ### Show a device
    Gets information on a single device, by `device_id` for a specific `user_id`.
    
    The API is:
    
    ```
    GET /_synapse/admin/v2/users/<user_id>/devices/<device_id>
    ```
    
    A response body like the following is returned:
    
    ```json
    {
      "device_id": "<device_id>",
      "display_name": "android",
      "last_seen_ip": "1.2.3.4",
    
      "last_seen_user_agent": "Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0",
    
      "last_seen_ts": 1474491775024,
      "user_id": "<user_id>"
    }
    ```
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - fully qualified: for example, `@user:server.com`.
    - `device_id` - The device to retrieve.
    
    **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.
      Absent if no name has been set.
    - `last_seen_ip` - The IP address where this device was last seen.
      (May be a few minutes out of date, for efficiency reasons).
    
      - `last_seen_user_agent` - The user agent of the device when it was last seen.
      (May be a few minutes out of date, for efficiency reasons).
    
    - `last_seen_ts` - The timestamp (in milliseconds since the unix epoch) when this
      devices was last seen. (May be a few minutes out of date, for efficiency reasons).
    - `user_id` - Owner of  device.
    
    ### Update a device
    Updates the metadata on the given `device_id` for a specific `user_id`.
    
    The API is:
    
    ```
    PUT /_synapse/admin/v2/users/<user_id>/devices/<device_id>
    
    {
      "display_name": "My other phone"
    }
    ```
    
    An empty JSON dict is returned.
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - fully qualified: for example, `@user:server.com`.
    - `device_id` - The device to update.
    
    The following fields are required in the JSON request body:
    
    - `display_name` - The new display name for this device. If not given,
      the display name is unchanged.
    
    ### Delete a device
    Deletes the given `device_id` for a specific `user_id`,
    and invalidates any access token associated with it.
    
    The API is:
    
    ```
    DELETE /_synapse/admin/v2/users/<user_id>/devices/<device_id>
    
    {}
    ```
    
    An empty JSON dict is returned.
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - fully qualified: for example, `@user:server.com`.
    - `device_id` - The device to delete.
    
    ## List all pushers
    Gets information about all pushers for a specific `user_id`.
    
    The API is:
    
    ```
    GET /_synapse/admin/v1/users/<user_id>/pushers
    ```
    
    A response body like the following is returned:
    
    ```json
    {
      "pushers": [
        {
          "app_display_name":"HTTP Push Notifications",
          "app_id":"m.http",
          "data": {
            "url":"example.com"
          },
          "device_display_name":"pushy push",
          "kind":"http",
          "lang":"None",
          "profile_tag":"",
          "pushkey":"a@example.com"
        }
      ],
      "total": 1
    }
    ```
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - fully qualified: for example, `@user:server.com`.
    
    **Response**
    
    The following fields are returned in the JSON response body:
    
    - `pushers` - An array containing the current pushers for the user
    
      - `app_display_name` - string - A string that will allow the user to identify
        what application owns this pusher.
    
      - `app_id` - string - This is a reverse-DNS style identifier for the application.
        Max length, 64 chars.
    
      - `data` - A dictionary of information for the pusher implementation itself.
    
        - `url` - string - Required if `kind` is `http`. The URL to use to send
          notifications to.
    
        - `format` - string - The format to use when sending notifications to the
          Push Gateway.
    
      - `device_display_name` - string -  A string that will allow the user to identify
        what device owns this pusher.
    
      - `profile_tag` - string - This string determines which set of device specific rules
        this pusher executes.
    
      - `kind` - string -  The kind of pusher. "http" is a pusher that sends HTTP pokes.
      - `lang` - string - The preferred language for receiving notifications
        (e.g. 'en' or 'en-US')
    
      - `profile_tag` - string - This string determines which set of device specific rules
        this pusher executes.
    
      - `pushkey` - string - This is a unique identifier for this pusher.
        Max length, 512 bytes.
    
    - `total` - integer - Number of pushers.
    
    See also the
    [Client-Server API Spec on pushers](https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers).
    
    
    ## Controlling whether a user is shadow-banned
    
    
    Shadow-banning is a useful tool for moderating malicious or egregiously abusive users.
    A shadow-banned users receives successful responses to their client-server API requests,
    but the events are not propagated into rooms. This can be an effective tool as it
    (hopefully) takes longer for the user to realise they are being moderated before
    pivoting to another account.
    
    Shadow-banning a user should be used as a tool of last resort and may lead to confusing
    or broken behaviour for the client. A shadow-banned user will not receive any
    notification and it is generally more appropriate to ban or kick abusive users.
    A shadow-banned user will be unable to contact anyone on the server.
    
    
    To shadow-ban a user the API is:
    
    
    ```
    POST /_synapse/admin/v1/users/<user_id>/shadow_ban
    ```
    
    
    To un-shadow-ban a user the API is:
    
    ```
    DELETE /_synapse/admin/v1/users/<user_id>/shadow_ban
    ```
    
    An empty JSON dict is returned in both cases.
    
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - The fully qualified MXID: for example, `@user:server.com`. The user must
      be local.
    
    ## Override ratelimiting for users
    
    This API allows to override or disable ratelimiting for a specific user.
    There are specific APIs to set, get and delete a ratelimit.
    
    ### Get status of ratelimit
    
    The API is:
    
    ```
    GET /_synapse/admin/v1/users/<user_id>/override_ratelimit
    ```
    
    A response body like the following is returned:
    
    ```json
    {
      "messages_per_second": 0,
      "burst_count": 0
    }
    ```
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - The fully qualified MXID: for example, `@user:server.com`. The user must
      be local.
    
    **Response**
    
    The following fields are returned in the JSON response body:
    
    - `messages_per_second` - integer - The number of actions that can
      be performed in a second. `0` mean that ratelimiting is disabled for this user.
    - `burst_count` - integer - How many actions that can be performed before
      being limited.
    
    If **no** custom ratelimit is set, an empty JSON dict is returned.
    
    ```json
    {}
    ```
    
    ### Set ratelimit
    
    The API is:
    
    ```
    POST /_synapse/admin/v1/users/<user_id>/override_ratelimit
    ```
    
    A response body like the following is returned:
    
    ```json
    {
      "messages_per_second": 0,
      "burst_count": 0
    }
    ```
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - The fully qualified MXID: for example, `@user:server.com`. The user must
      be local.
    
    Body parameters:
    
    - `messages_per_second` - positive integer, optional. The number of actions that can
      be performed in a second. Defaults to `0`.
    - `burst_count` - positive integer, optional. How many actions that can be performed
      before being limited. Defaults to `0`.
    
    To disable users' ratelimit set both values to `0`.
    
    **Response**
    
    The following fields are returned in the JSON response body:
    
    - `messages_per_second` - integer - The number of actions that can
      be performed in a second.
    - `burst_count` - integer - How many actions that can be performed before
      being limited.
    
    ### Delete ratelimit
    
    The API is:
    
    ```
    DELETE /_synapse/admin/v1/users/<user_id>/override_ratelimit
    ```
    
    An empty JSON dict is returned.
    
    ```json
    {}
    ```
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - The fully qualified MXID: for example, `@user:server.com`. The user must
      be local.
    
    ## Check username availability
    
    Checks to see if a username is available, and valid, for the server. See [the client-server
    
    API](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-register-available)
    for more information.
    
    
    This endpoint will work even if registration is disabled on the server, unlike
    
    `/_matrix/client/r0/register/available`.
    
    The API is:
    
    ```
    
    GET /_synapse/admin/v1/username_available?username=$localpart
    
    The request and response format is the same as the
    [/_matrix/client/r0/register/available](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-register-available) API.
    
    ## Find a user based on their ID in an auth provider
    
    
    The API is:
    
    ```
    GET /_synapse/admin/v1/auth_providers/$provider/users/$external_id
    ```
    
    When a user matched the given ID for the given provider, an HTTP code `200` with a response body like the following is returned:
    
    ```json
    {
        "user_id": "@hello:example.org"
    }
    ```
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `provider` - The ID of the authentication provider, as advertised by the [`GET /_matrix/client/v3/login`](https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3login) API in the `m.login.sso` authentication method.
    - `external_id` - The user ID from the authentication provider. Usually corresponds to the `sub` claim for OIDC providers, or to the `uid` attestation for SAML2 providers.
    
    The `external_id` may have characters that are not URL-safe (typically `/`, `:` or `@`), so it is advised to URL-encode those parameters.
    
    **Errors**
    
    Returns a `404` HTTP status code if no user was found, with a response body like this:
    
    ```json
    {
        "errcode":"M_NOT_FOUND",
        "error":"User not found"
    }
    ```
    
    _Added in Synapse 1.68.0._
    
    ## Find a user based on their Third Party ID (ThreePID or 3PID)
    
    
    The API is:
    
    ```
    GET /_synapse/admin/v1/threepid/$medium/users/$address
    ```
    
    When a user matched the given address for the given medium, an HTTP code `200` with a response body like the following is returned:
    
    ```json
    {
        "user_id": "@hello:example.org"
    }
    ```
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `medium` - Kind of third-party ID, either `email` or `msisdn`.
    - `address` - Value of the third-party ID.
    
    The `address` may have characters that are not URL-safe, so it is advised to URL-encode those parameters.
    
    **Errors**
    
    Returns a `404` HTTP status code if no user was found, with a response body like this:
    
    ```json
    {
        "errcode":"M_NOT_FOUND",
        "error":"User not found"
    }
    ```
    
    _Added in Synapse 1.72.0._
    
    This endpoint allows an admin to redact the events of a given user. There are no restrictions on redactions for a 
    local user. By default, we puppet the user who sent the message to redact it themselves. Redactions for non-local users are issued using the admin user, and will fail in rooms where the admin user is not admin/does not have the specified power level to issue redactions. 
    
    
    The API is 
    ```
    POST /_synapse/admin/v1/user/$user_id/redact
    
    {
      "rooms": ["!roomid1", "!roomid2"]
    }
    ```
    If an empty list is provided as the key for `rooms`, all events in all the rooms the user is member of will be redacted, 
    otherwise all the events in the rooms provided in the request will be redacted. 
    
    The API starts redaction process running, and returns immediately with a JSON body with
    a redact id which can be used to query the status of the redaction process:
    
    ```json
    {
        "redact_id": "<opaque id>"
    }
    ```
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    - `user_id` - The fully qualified MXID of the user: for example, `@user:server.com`.
    
    The following JSON body parameter must be provided:
    
    -  `rooms` - A list of rooms to redact the user's events in. If an empty list is provided all events in all rooms
      the user is a member of will be redacted
    
    The following JSON body parameters are optional:
    
    - `reason` - Reason the redaction is being requested, ie "spam", "abuse", etc. This will be included in each redaction event, and be visible to users.
    - `limit` - a limit on the number of the user's events to search for ones that can be redacted (events are redacted newest to oldest) in each room, defaults to 1000 if not provided
    
    
    
    ## Check the status of a redaction process
    
    It is possible to query the status of the background task for redacting a user's events.
    The status can be queried up to 24 hours after completion of the task,
    or until Synapse is restarted (whichever happens first).
    
    The API is:
    
    ```
    GET /_synapse/admin/v1/user/redact_status/$redact_id
    ```
    
    A response body like the following is returned:
    
    ```
    {
      "status": "active",
      "failed_redactions": [],
    }
    ```
    
    **Parameters**
    
    The following parameters should be set in the URL:
    
    * `redact_id` - string - The ID for this redaction process, provided when the redaction was requested.
    
    
    **Response**
    
    The following fields are returned in the JSON response body:
    
    - `status` - string - one of scheduled/active/completed/failed, indicating the status of the redaction job
    - `failed_redactions` - dictionary - the keys of the dict are event ids the process was unable to redact, if any, and the values are 
      the corresponding error that caused the redaction to fail
    
    
    _Added in Synapse 1.116.0._