---
type: api
title: Login to ECE
description: Authenticates against available users.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/cloud-enterprise/v4/operation/operation-login
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/cloud-enterprise/v4/operation/operation-login
products:
  - Elastic Cloud Enterprise
---

# Login to ECE

## Paths

- `POST` `/users/auth/_login`

- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/cloud-enterprise/v4/authentication#basicauth)
- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/cloud-enterprise/v4/authentication#apikey)

## Description

Authenticates against available users.

## Request Body

`application/json`

The login request

- `username` (string) — required
  The username part of the login request
- `password` (string) — required
  The plain text password part of the login request
- `login_state` ({} LoginState) — optional
  Configure how the API responds after a successful login.
  - `path` (string) — optional
    The path to which to redirect post login - if not specified then no redirect is performed, instead 200 is returned with the token in the body

## Responses

#### `200`

Login successful, returns the token in the body (if 'login_state.path' not specified)

`application/json`

- `token` (string)
  The authorization bearer token that you use in subsequent requests
- `session_expiration_time` (string)
  The time that the session token will expire
#### `302`

Redirects to '/sso/token#BEARER_TOKEN?state=LOGIN_STATE' with the fragment containing a bearer token  (if 'login_state.path' is specified)

`application/json`

Type: `EmptyResponse`

#### `401`

The supplied authentication is invalid. (code: `root.unauthenticated`)

`application/json`

- `errors` ([] BasicFailedReplyElement)
  A list of errors that occurred in the failing request
  - `code` (string)
    A structured code representing the error type that occurred
  - `message` (string)
    A human readable message describing the error that occurred
  - `fields` ([] string)
    If the error can be tied to a specific field or fields in the user request, this lists those fields
##### Response Headers

- `x-cloud-error-codes` (enum)
  The error codes associated with the response

#### `501`

The administrator needs to configure the authentication cluster. (code: `authc.no_authentication_cluster`)

`application/json`

- `errors` ([] BasicFailedReplyElement)
  A list of errors that occurred in the failing request
  - `code` (string)
    A structured code representing the error type that occurred
  - `message` (string)
    A human readable message describing the error that occurred
  - `fields` ([] string)
    If the error can be tied to a specific field or fields in the user request, this lists those fields
##### Response Headers

- `x-cloud-error-codes` (enum)
  The error codes associated with the response

#### `502`

The authentication cluster failed to process the request. The response body contains details about the error. (code: `authc.authentication_cluster_error`)

`application/json`

- `errors` ([] BasicFailedReplyElement)
  A list of errors that occurred in the failing request
  - `code` (string)
    A structured code representing the error type that occurred
  - `message` (string)
    A human readable message describing the error that occurred
  - `fields` ([] string)
    If the error can be tied to a specific field or fields in the user request, this lists those fields
##### Response Headers

- `x-cloud-error-codes` (enum)
  The error codes associated with the response

## Code Examples

#### Console

```console
POST /users/auth/_login
```

#### curl

```curl
curl -X POST "/users/auth/_login"
```

