---
title: "Authentication"
description: ""
url: "https://docs.itrsgroup.com/docs/opsview/6.11.7/rest-api/rest-api-overview/api-authentication/index.html"
---
There is process flow for authenticating to Opsview within the [Introduction](https://docs.itrsgroup.com/docs/opsview/6.11.7/rest-api/rest-api-background/api-introduction/index.html) in the `Authentication` section

## Logging in

URL: `/rest/login`

- `GET` — unimplemented.
- `POST` — get session token. Pass in username and password.
- `PUT` — unimplemented.
- `DELETE` — if session token is valid, deletes from session list, effectively a logout.


**Note**


The [opsview_rest](https://docs.itrsgroup.com/docs/opsview/6.11.7/rest-api/rest-api-background/api-common-examples/index.html#opsview_rest) command will automatically take care of authentication for you without having to post credentials to the login endpoint.



If a token cannot be generated, a 503 HTTP status code will be returned, with the text, “Error creating session token after 5 attempts”.

Example `curl` request:

```
curl -H 'Content-Type: application/json' -X 'application/json' -X POST -d '{"username":"admin","password":"initial"}' http://localhost/rest/login
```

Example response:

```
{
    "token": "7cd5652f7bfde4220211d063c166b263160a7d52"
}
```

The length of the token is 32 characters.

If you can pass the parameter, `include_user_data=1`, a `user_data` field will be returned in the response. This will contain the data from the `/rest/user` call.

## Logging out

URL: `/rest/logout`

- `POST` — deletes the session.
- `GET`, `PUT`, `DELETE` — unimplemented.

Example `opsview_rest` request

```
opsview_rest --token-file /path/to/opsview_restapi_token --data-format=json --pretty POST logout
```


**Note**


For more information on how to generate and use the token file, see [opsview_rest](https://docs.itrsgroup.com/docs/opsview/6.11.7/rest-api/rest-api-background/api-common-examples/index.html#opsview_rest) documentation.



Expected response:

```
{
   "logout_via" : "REST API"
}
```

## User information

URL: `/rest/user`

- `GET` — returns user information for the currently authenticated user.
- `POST`, `PUT`, `DELETE` — unimplemented.

This returns information about the user.

See  `include_user_data=1` in the `login` section above for fetching this information via a curl request when authenticating.

Example `opsview_rest` request:

```
opsview_rest --token-file /path/to/opsview_restapi_token --pretty GET user
```

Example response:

```
{
    "access_list": {
        "ACTIONALL": 1,
        "ADMINACCESS": 1,
        "VIEWALL": 1,
        ...
    },
    "fullname": "Admin user",
    "language": "",
    "name": "admin",
    "realm": "local",
    "role": "Administrator"
}
```


