---
title: "Initialize Login Flow for APIs, Services, Apps, ..."
method: GET
path: "/self-service/login/api"
tags: ["v0alpha2"]
---

# Initialize Login Flow for APIs, Services, Apps, ...

`GET /self-service/login/api`

This endpoint initiates a login flow for API clients that do not use a browser, such as mobile devices, smart TVs, and so on.

If a valid provided session cookie or session token is provided, a 400 Bad Request error
will be returned unless the URL query parameter `?refresh=true` is set.

To fetch an existing login flow call `/self-service/login/flows?flow=<flow_id>`.

You MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server
Pages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make
you vulnerable to a variety of CSRF attacks, including CSRF login attacks.

In the case of an error, the `error.id` of the JSON response body can be one of:

`session_already_available`: The user is already signed in.
`session_aal1_required`: Multi-factor auth (e.g. 2fa) was requested but the user has no session yet.
`security_csrf_violation`: Unable to fetch the flow because a CSRF violation occurred.

This endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).

More information can be found at [Ory Kratos User Login](https://www.ory.sh/docs/kratos/self-service/flows/user-login) and [User Registration Documentation](https://www.ory.sh/docs/kratos/self-service/flows/user-registration).

## Query parameters

- `refresh` boolean
- `aal` string

## Headers

- `X-Session-Token` string

## Response `200`

selfServiceLoginFlow

- SelfServiceLoginFlow — This object represents a login flow. A login flow is initiated at the "Initiate Login API / Browser Flow" endpoint by a client. Once a login flow is completed successfully, a session cookie or session token will be issued.
  - `active` 'password' | 'totp' | 'oidc' | 'webauthn' | 'lookup_secret' — and so on.
  - `created_at` string, date-time — CreatedAt is a helper struct field for gobuffalo.pop.
  - `expires_at` string, date-time, required — ExpiresAt is the time (UTC) when the flow expires. If the user still wishes to log in, a new flow has to be initiated.
  - `id` string, uuid4, required
  - `issued_at` string, date-time, required — IssuedAt is the time (UTC) when the flow started.
  - `refresh` boolean — Refresh stores whether this login flow should enforce re-authentication.
  - `request_url` string, required — RequestURL is the initial URL that was requested from Ory Kratos. It can be used to forward information contained in the URL's path or query for example.
  - `requested_aal` 'aal0' | 'aal1' | 'aal2' | 'aal3' — The authenticator assurance level can be one of "aal1", "aal2", or "aal3". A higher number means that it is harder for an attacker to compromise the account. Generally, "aal1" implies that one authentication factor was used while AAL2 implies that two factors (e.g. password + TOTP) have been used. To learn more about these levels please head over to: https://www.ory.sh/kratos/docs/concepts/credentials
  - `return_to` string — ReturnTo contains the requested return_to URL.
  - `type` string, required — The flow type can either be `api` or `browser`.
  - `ui` UiContainer, required — Container represents a HTML Form. The container can work with both HTTP Form and JSON requests
    - `action` string, required — Action should be used as the form action URL `<form action="{{ .Action }}" method="post">`.
    - `messages` UiText[]
      - `context` object — The message's context. Useful when customizing messages.
      - `id` integer, required
      - `text` string, required — The message text. Written in american english.
      - `type` string, required
    - `method` string, required — Method is the form method (e.g. POST)
    - `nodes` UiNode[], required
      - `attributes` union, required
        - UiNodeInputAttributes — InputAttributes represents the attributes of an input node
          - `disabled` boolean, required — Sets the input's disabled field to true or false.
          - `label` UiText
            - `context` object — The message's context. Useful when customizing messages.
            - `id` integer, required
            - `text` string, required — The message text. Written in american english.
            - `type` string, required
          - `name` string, required — The input's element name.
          - `node_type` string, required — NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "input".
          - `onclick` string — OnClick may contain javascript which should be executed on click. This is primarily used for WebAuthn.
          - `pattern` string — The input's pattern.
          - `required` boolean — Mark this input field as required.
          - `type` string, required
          - `value` unknown
        - UiNodeTextAttributes
          - `id` string, required — A unique identifier
          - `node_type` string, required — NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "text".
          - `text` UiText, required
            - `context` object — The message's context. Useful when customizing messages.
            - `id` integer, required
            - `text` string, required — The message text. Written in american english.
            - `type` string, required
        - UiNodeImageAttributes
          - `height` integer, required — Height of the image
          - `id` string, required — A unique identifier
          - `node_type` string, required — NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "img".
          - `src` string, required — The image's source URL. format: uri
          - `width` integer, required — Width of the image
        - UiNodeAnchorAttributes
          - `href` string, required — The link's href (destination) URL. format: uri
          - `id` string, required — A unique identifier
          - `node_type` string, required — NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "a".
          - `title` UiText, required
            - `context` object — The message's context. Useful when customizing messages.
            - `id` integer, required
            - `text` string, required — The message text. Written in american english.
            - `type` string, required
        - UiNodeScriptAttributes
          - `async` boolean, required — The script async type
          - `crossorigin` string, required — The script cross origin policy
          - `id` string, required — A unique identifier
          - `integrity` string, required — The script's integrity hash
          - `node_type` string, required — NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "script".
          - `nonce` string, required — Nonce for CSP A nonce you may want to use to improve your Content Security Policy. You do not have to use this value but if you want to improve your CSP policies you may use it. You can also choose to use your own nonce value!
          - `referrerpolicy` string, required — The script referrer policy
          - `src` string, required — The script source
          - `type` string, required — The script MIME type
      - `group` 'default' | 'password' | 'oidc' | 'profile' | 'link' | 'totp' | 'lookup_secret' | 'webauthn', required — Group specifies which group (e.g. password authenticator) this node belongs to.
      - `messages` UiText[], required
        - `context` object — The message's context. Useful when customizing messages.
        - `id` integer, required
        - `text` string, required — The message text. Written in american english.
        - `type` string, required
      - `meta` UiNodeMeta, required — This might include a label and other information that can optionally be used to render UIs.
        - `label` UiText
          - `context` object — The message's context. Useful when customizing messages.
          - `id` integer, required
          - `text` string, required — The message text. Written in american english.
          - `type` string, required
      - `type` 'text' | 'input' | 'img' | 'a' | 'script', required — The node's type
  - `updated_at` string, date-time — UpdatedAt is a helper struct field for gobuffalo.pop.

## Other responses

- `400` — jsonError
- `500` — jsonError

## Changes

- **2022-06-01** `fca041c7721f` — 13 warning, 2 info
  - added the new `a` enum value to the `ui/nodes/items/type` response property for the response status `200`
  - added the new `default` enum value to the `ui/nodes/items/group` response property for the response status `200`
  - added the new `img` enum value to the `ui/nodes/items/type` response property for the response status `200`
  - added the new `input` enum value to the `ui/nodes/items/type` response property for the response status `200`
  - …11 more
- **2022-03-22** `028a4cf83c15` — 2 warning, 3 info
  - added the new `lookup_secret` enum value to the `active` response property for the response status `200`
  - added the new `webauthn` enum value to the `active` response property for the response status `200`
  - the response property `ui/nodes/items/attributes/oneOf[subschema #3: ImageAttributes represents the attributes of an image node.]/height` became required for the status `200`
  - the response property `ui/nodes/items/attributes/oneOf[subschema #3: ImageAttributes represents the attributes of an image node.]/width` became required for the status `200`
  - …1 more
- …earlier changes not shown

[Full history](https://skmtc.dev/ory/apis/ory-identities-api/changes/self-service/login/api/get.md)

---

[API](https://skmtc.dev/ory/apis/ory-identities-api.md) · [All operations](https://skmtc.dev/ory/apis/ory-identities-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/ory/ory-identities-api/revisions/fca041c7721f/schema)
