Question: In the [Matrix](https://matrix.org/) instant messaging protocol, when using the reference implementation of the Matrix server (called `synapse`), there is an [admin API](https://github.com/matrix-org/synapse/blob/master/docs/admin_api/) with functions like [resetting a password](https://github.com/matrix-org/synapse/blob/master/docs/admin_api/user_admin_api.rst#reset-password) for a user etc..

Accessing this requires an [`access_token`](https://matrix.org/docs/spec/client_server/latest#using-access-tokens) "API key" of a server admin user.

How do I get one?

Answer: 
These `access_token` API keys were listed in the [Riot](https://riot.im/) web application until not too long ago, somewhere under the account settings. In the newest version, I could no longer find them there.

So instead, I use a technique I found [here](https://github.com/matrix-org/synapse/issues/1707#issuecomment-405455882), which is basically a login procedure done with `curl`. The server's answer will contain the `access_token`.

1. Find out the Matrix user ID and password of a server admin user. The username has to be in the fully qualified form, for example `@user:example.com`.
2. Execute the following command on a Linux-based system that has `curl` installed. Of course, supply the address of you Matrix server for `example.com`, and also your Matrix user ID and password.

```
curl -XPOST \
  -d '{"type":"m.login.password", "user":"<userid>", "password":"<password>"}' \
  "https://example.com:8448/_matrix/client/r0/login"

```
With the current version of the Matrix protocol, getting an access\_token programmatically works slightly different:

To find out the endpoint, e.g., for matrix.org, you need to check a `.well-known` file for the API URL ([Documentation](https://spec.matrix.org/v1.1/client-server-api/#well-known-uri)): `https://matrix.org/.well-known/matrix/client`:

```
$ curl https://matrix.org/.well-known/matrix/client
{
    "m.homeserver": {
        "base_url": "https://matrix-client.matrix.org"
    },
    "m.identity_server": {
        "base_url": "https://vector.im"
    }
}

```

Afterwards, the homeserver base url can be used for the curl call ([See Documentation for the /login endpoint](https://spec.matrix.org/v1.1/client-server-api/#post_matrixclientv3login)):

```
$ curl '{"type":"m.login.password", "user":"'$username'", "password":"'$password'"} \ 
"https://$base_url/_matrix/client/v3/login"

{
  "user_id":"@username:matrix.org",
  "access_token":"token",
  "home_server":"matrix.org",
  "device_id":"ID",
  "well_known": { 
    "m.homeserver": {
      "base_url":"https://matrix-client.matrix.org/"
    }
  }
}

```