# Fetch a session

Fetch an ID Check session to get its current state.

```http
GET https://handover.prod.idcheck.bankid.no/api/v1/session/<<SESSION_ID>>
```

> **The state is not proof of identity**
>
> The state is for convenience only, and it is not always up to date. Never use it to make a decision about the user or their identity. Base each decision on the results, after the checks in [Check the results](https://docs.stoe.no/id-check.md#check-the-results).

The [Handover API spec](https://docs.stoe.no/id-check/openapi.md) gives the full response schema.

## How it fits

Poll this endpoint to follow the `state` of the session. Use the state only to give feedback to the user.

- Poll from the merchant's server, because the request needs the access token.
- Poll at most once every 3 seconds.
- Stop when the state is final: `completed`, `failed`, `aborted` or `expired`.
- Get a new access token when the current one expires. The token response gives its lifetime in seconds, in `expires_in`.

For the full flow, see the [process overview](https://docs.stoe.no/id-check.md#process-overview).

## Request

Send an access token with the `handover:read` scope. See [Authentication](https://docs.stoe.no/id-check/authentication.md).

Replace `<<SESSION_ID>>` with the `id` from the [create response](https://docs.stoe.no/id-check/create-session.md#response). The spec calls this path parameter `bindingId`. Do not send a body.

```http
GET /api/v1/session/<<SESSION_ID>> HTTP/1.1
Host: handover.prod.idcheck.bankid.no
Authorization: Bearer <<ACCESS_TOKEN>>
```

## Response

A successful request returns `200 OK` and the session in `payload`. The session has the same properties as the [create response](https://docs.stoe.no/id-check/create-session.md#response).

This example shows a session that failed because the identity document failed the checks:

```json
{
  "payload": {
    "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "branch_id": "e2c236a3-01f2-44a6-bb2a-1350938d84e4",
    "human_id": "not-used-1234",
    "client_reference": "2e496a55-3b51-4180-be71-bfd396043065",
    "state": "failed",
    "code": "BAD_DOCUMENT",
    "reason": "REIDENTIFICATION",
    "artefact_type": "PDF",
    "success_url": "https://example.com/id-check/success?id=3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "failure_url": "https://example.com/id-check/failure?id=3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "intent_url": "https://prod.idcheck.bankid.no/start?handoverId=3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "last_update": "2021-06-22T11:56:41.020Z",
    "qr_svg_path": "<<SVG_PATH_DATA>>",
    "play_store_url": null,
    "apple_store_url": null
  },
  "request_id": "request:6c1e2f3a-8b4d-4e5f-9a6b-7c8d9e0f1a2b",
  "response_id": "response:6c1e2f3a-8b4d-4e5f-9a6b-7c8d9e0f1a2b",
  "timestamp": "2021-06-22T11:56:43.512Z"
}
```

Because a `GET` request has no body, `request_id` is the value of the `X-Request-Id` header of the request. Without this header, the Handover API makes an ID.

- A session can skip states, so a poll does not always show each state. See [Session states](https://docs.stoe.no/id-check/create-session.md#session-states).
- If the user stops, the state changes to `failed` with the code `ABANDONED`. This occurs after 15 minutes without progress, or 1 hour after the user started the session.
- A state update can arrive late, or not at all. Set a time limit, and stop polling after that time.
- An expired session returns `200 OK` with the state `expired`.
- Handle unknown states and codes. See [Session states](https://docs.stoe.no/id-check/create-session.md#session-states) and [Failure codes](https://docs.stoe.no/id-check/create-session.md#failure-codes).

## Errors

Errors have the same format as in [Create a session](https://docs.stoe.no/id-check/create-session.md#errors).

| Status                      | `code`                | Cause                                                                                                        |
| --------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------ |
| `400 Bad Request`           | `EINVALIDREQUEST`     | The request has a body without `request_id` or `payload`.                                                    |
| `401 Unauthorized`          | `EUNAUTHORISED`       | The access token is not valid or has expired.                                                                |
| `403 Forbidden`             | `EFORBIDDEN`          | The request has no `Authorization` header, or the access token does not have the `handover:read` scope.      |
| `404 Not Found`             | `ESESSIONMISSING`     | The session ID is not a UUID, the session does not exist, or the session belongs to a different integration. |
| `406 Not Acceptable`        | `EINVALIDCONTENTTYPE` | The request has a `Content-Type` header with a value other than `application/json`.                          |
| `500 Internal Server Error` | `EUNKNOWN`            | An error occurred in the Handover API.                                                                       |

## Next steps

- [Create a session](https://docs.stoe.no/id-check/create-session.md): start a new session.
- [Receive the results](https://docs.stoe.no/id-check.md#receive-the-results): how ID Check sends the results of a completed session.
- [Check the results](https://docs.stoe.no/id-check.md#check-the-results): verify the results and compare them with the expected customer.
- [Handover API spec](https://docs.stoe.no/id-check/openapi.md): the full response schema.
