docs: update doc to include how to get the API token (#6381)

This commit is contained in:
Kelvin Oghenerhoro Omereshone 2022-06-29 20:07:07 +01:00 committed by GitHub
parent 22382c757c
commit acdb9a9c0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -273,7 +273,37 @@ fleetctl user create --name "API User" --email api@example.com --password temp!p
Now that your new user is all set up, you will need to log in with `fleetctl login`. You'll now be able to perform tasks using `fleetctl` as your new API-only user.
> If you are using a version of Fleet older than `4.13.0`, you will need to [reset the API-only user's password](https://github.com/fleetdm/fleet/blob/a1eba3d5b945cb3339004dd1181526c137dc901c/docs/Using-Fleet/fleetctl-CLI.md#reset-the-password) before running queries.
> If you are using a version of Fleet older than `4.13.0`, you will need to [reset the API-only user's password](https://github.com/fleetdm/fleet/blob/a1eba3d5b945cb3339004dd1181526c137dc901c/docs/Using-Fleet/fleetctl-CLI.md#reset-the-password) before running queries.
### Get the API token of an API-only user
To get the API key of an API-only user, you need to call the Login API with the credentials that were supplied during user creation.
For example say the credentials provided was `api@fleetdm.com` for the email and `foobar12345` for the password. You may call the [Log in API](https://fleetdm.com/docs/using-fleet/rest-api#log-in) like so:
```sh
curl --location --request POST 'https://myfleetdomain.com/api/v1/fleet/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "api@fleetdm.com",
"password": "foobar12345"
}'
```
The [Log in API](https://fleetdm.com/docs/using-fleet/rest-api#log-in) will return a response similar to the one below with the API token included which will not expire.
```json
{
"user": {
"id": 82,
"name": "API User",
"email": "api@fleetdm.com",
"global_role": "observer",
"api_only": true
},
"available_teams": [],
"token": "foo_token"
}
```
### Switching users