---
title: "Manage App Users and Sessions"
description: "Manage backend user records, enrollment, and device sessions within a deployment."
permalink: /docs/backend-api/api-reference/manage-app-users-and-sessions/
---
# Manage App Users and Sessions

The project configures an app-user model, commonly named `user`. Records of that model in a deployment represent people who can enroll in the app. Additional metadata supports enrollment and session management.

A single user may have one or more *sessions*. A session represents a single device that is (or was) signed in.

<Info title={"Deployment users and authentication-scope app users"}>

This API operates on the user records and sessions inside one deployment backend. See [Users in deployments](/docs/concepts/users-and-access/users-in-deployments/) for how these records relate to app users.

Direct enrollment links or QR codes can create a session for a backend user without an authentication-scope assignment. Deleting a backend user through this API is different from deleting the central app-user identity in OVERRIDE.

</Info>

<Info>

To allow a user to have more than one session, the "Multiple devices per user" feature flag must be enabled for the application.

</Info>

### Parameters

To retrieve, create, update or delete mobile users, follow the instructions in these sections of the documentation for your mobile user object type (e.g. **user**):

* [Retrieve all Objects](/docs/backend-api/api-reference/retrieve-all-objects/)
* [Create a New Object](/docs/backend-api/api-reference/create-a-new-object/)
* [Update a Single Object](/docs/backend-api/api-reference/update-a-single-object/)
* [Delete a Single Object](/docs/backend-api/api-reference/delete-a-single-object/)

<Warning>

Deleting the backend **user** object locks that user and requests a wipe of its enrolled devices’ app data. Devices apply the request when they receive the backend response. This operation is irreversible and can remove local changes that have not synchronized.

</Warning>

Before Runtime 4.70, the backend reported only the installed Container version. From Runtime 4.70 it also reported the Runtime version, but labeled it as the "container version." From Runtime 4.82, both versions are reported correctly.

### User and Sessions API

| API | Relative URL | HTTP Request Method |
| --- | --- | --- |
| [List all users](#list-all-users) | `/api/v4/backend-deployment-id/users` | GET |
| [Get user and sessions](#get-single-user) | `/api/v4/backend-deployment-id/users/user-id` | GET |
| [Get single session](#get-single-session) | `/api/v4/backend-deployment-id/users/user-id/sessions/session-id` | GET |
| [Lock user](#lock-user) | `/api/v4/backend-deployment-id/users/user-id/lock` | POST |
| [Unlock user](#unlock-user) | `/api/v4/backend-deployment-id/users/user-id/unlock` | POST |
| [Wipe session](#wipe-session) | `/api/v4/backend-deployment-id/users/user-id/sessions/session-id/wipe` | POST |
| [Re-authenticate session](#re-authenticate-session) | `/api/v4/backend-deployment-id/users/user-id/sessions/session-id/re-authenticate` | POST |
| [Generate authentication token](#generate-authentication-token) | `/api/v4/backend-deployment-id/users/user-id/authentication-token` | POST |

<Info title={"BASE-URL"}>

The below examples contain a `BASE-URL` placeholder. Please refer to the [HTTP Endpoints](/docs/backend-api/introduction/#http-endpoints) section to get the base URL relevant to your deployment.

</Info>

#### List all users

API:

```http
GET BASE-URL/api/v4/backend-deployment-id/users[?limit=x&skip=y]
```

##### Sample request

```
GET BASE-URL/api/v4/533bda53027894f69b001055/users?limit=2&skip=0
```

##### Response example

**json**

```json
{
  "total": 47,
  "count": 2,
  "more": true,
  "objects": [
  {
    "id": "c8c8c4f8-5013-11e7-a8c7-04017e679e01",
    "last_connected_at": "2017-08-18T13:33:23Z",
    "enrolled": false,
    "locked": false,
    "sessions": [
      {
        "id": "9469407e-8417-11e7-825d-040151508301",
        "state": "LOCKED",
        "last_authenticated_at": "2017-08-18T13:17:26Z",
        "created_at": "2017-08-18T13:17:26Z",
        "signed_out_at": "2017-08-18T13:33:23Z",
        "last_connected_at": "2017-08-18T13:33:23Z",
        "container": {
          "version": "20.6.1",
          "bundle_id": "xyz.appinstall.myapp",
          "platform": "IOS"
        },
        "runtime": {
          "version": "4.82.0"
        },
        "device": {
          "id": "1234-1234-1234-1234"
        },
        "label": "Apple iPhone7,2",
        "sync_status": {
          "last_full_sync": "2018-07-31T12:17:58Z"
        }
      }
    ]
  },
  {
    "id": "5571fb26-54f7-11e7-a8f8-040151508301",
    "last_connected_at": "2017-08-23T10:12:57Z",
    "enrolled": true,
    "locked": false,
    "sessions": [
      {
        "id": "066b26c4-8418-11e7-9ba9-04017e679e01",
        "state": "ENROLLED",
        "last_authenticated_at": "2017-08-18T13:20:37Z",
        "created_at": "2017-08-18T13:20:37Z",
        "signed_out_at": null,
        "last_connected_at": "2017-08-23T10:12:57Z",
        "container": {
          "version": "20.6.1",
          "bundle_id": "xyz.appinstall.myapp",
          "platform": "ANDROID"
        },
        "runtime": {
          "version": "4.82.0"
        },
        "device": {
          "id": "2345-2345-2345-2345"
        },
        "label": "Sony C6903"
      },
      {
        "id": "556ed8a6-54f7-11e7-a8f8-040151508301",
        "state": "LOCKED",
        "last_authenticated_at": null,
        "created_at": null,
        "signed_out_at": "2017-08-18T13:20:30Z",
        "last_connected_at": "2017-06-19T14:19:39Z",
        "container": {
          "version": "20.6.1",
          "bundle_id": "xyz.appinstall.myapp",
          "platform": "CHROME"
        },
        "runtime": {
          "version": "4.82.0"
        },
        "device": {
          "id": "3456-3456-3456-3456"
        },
        "label": "Chrome"
      }
    ]
  }
]
}
```

#### Get single user

API:

```
GET /api/v4/backend-deployment-id/users/user-id
```

##### Sample request

```
GET BASE-URL/api/v4/533bda53027894f69b001055/users/c8c8c4f8-5013-11e7-a8c7-04017e679e01
```

##### Response example

**json**

```json
{
    "id": "c8c8c4f8-5013-11e7-a8c7-04017e679e01",
    "last_connected_at": "2017-08-18T13:33:23Z",
    "enrolled": false,
    "locked": false,
    "sessions": [
        {
            "id": "9469407e-8417-11e7-825d-040151508301",
            "state": "LOCKED",
            "last_authenticated_at": "2017-08-18T13:17:26Z",
            "created_at": "2017-08-18T13:17:26Z",
            "signed_out_at": "2017-08-18T13:33:23Z",
            "last_connected_at": "2017-08-18T13:33:23Z",
            "container": {
                "version": "20.6.1",
                "bundle_id": "xyz.appinstall.myapp",
                "platform": "IOS"
            },
            "runtime": {
                "version": "4.82.0"
            },
            "device": {
              "id": "3456-3456-3456-3456"
            },
            "label": "Apple iPhone7,2",
            "sync_status": {
                "last_full_sync": "2018-07-31T12:17:58Z"
            }
        }
    ]
}
```

#### Get single session

API:

```
GET /api/v4/backend-deployment-id/users/user-id/sessions/session-id
```

##### Sample request

```
GET BASE-URL/api/v4/533bda53027894f69b001055/users/c8c8c4f8-5013-11e7-a8c7-04017e679e01/sessions/9469407e-8417-11e7-825d-040151508301
```

##### Response example

**json**

```json
{
    "id": "9469407e-8417-11e7-825d-040151508301",
    "state": "LOCKED",
    "last_authenticated_at": "2017-08-18T13:17:26Z",
    "created_at": "2017-08-18T13:17:26Z",
    "signed_out_at": "2017-08-18T13:33:23Z",
    "last_connected_at": "2017-08-18T13:33:23Z",
    "container": {
        "version": "20.6.1",
        "bundle_id": "xyz.appinstall.myapp",
        "platform": "IOS"
    },
    "runtime": {
        "version": "4.82.0"
    },
    "device": {
      "id": "3456-3456-3456-3456"
    },
    "label": "Apple iPhone7,2",
    "sync_status": {
        "last_full_sync": "2018-07-31T12:17:58Z"
    }
}
```

Fields:

| Field | Description |
| --- | --- |
| `state` | `ENROLLED`: Currently enrolled.`LOCKED`: Locked via backend, API, or from the device. Will direct user to the login screen on next connect.`RESET`: Like locked, but will force a data wipe the next time the device connects.`NEVER_ENROLLED`: Only for legacy data. |
| `last_connected_at` | Updated every time the device connects via an API call, such as sync or data upload. |
| `created_at` | First enrollment date for this session. |
| `last_authenticated_at` | Date of the last enrollment call. Should be close to `created_at` if this is the first enrollment (may not match exactly). |
| `signed_out_at` | Date of last sign out (when the state changed to `LOCKED` or `RESET`). Stays present when the session enrolls again. |

Apart from `last_connected_at`, these values only change when the user enrolls or the session is "locked". Note that in typical cases, the same session is used over multiple enrollments if the same device is used, but a new session is created if the user enrolls using a different device.

#### Lock user

Locking the user will automatically disable the application on all of their devices, as well as prevent them from logging in again.

<Info>

**Note:** A user can be unlocked, in which case they will be able to log in again.

</Info>

If *`wipe`* is true, all application data on the device will be permanently deleted. This can include any data or attachments that have not uploaded to the Backend yet. This action cannot be undone.

API:

```
POST /api/v4/backend-deployment-id/users/user-id/lock

{"wipe": true/false}
```

Or use the [batch operation](/docs/backend-api/api-reference/batch-operations-v4-api/):

```json
{
    "method": "users/lock",
    "user_id": "...",
    "wipe": true/false
}
```

<Warning>

**Note:** the *wipe* parameter is required.

</Warning>

The response code is 204 if successful.

#### Unlock user

Allow a locked user to log in again.

API:

```
POST /api/v4/backend-deployment-id/users/user-id/unlock
```

Or use the [batch operation](/docs/backend-api/api-reference/batch-operations-v4-api/):

```json
{
    "method": "users/unlock",
    "user_id": "..."
}
```

The response code is 204 if successful.

#### Wipe session

This requests permanent deletion of the session’s local application data when the device receives the backend response. This can include data or attachments that have not uploaded yet. It does not delete the deployment’s backend records. This action cannot be undone.

This does not affect any other sessions, and the user will still be able to log in.

API:

```
POST /api/v4/backend-deployment-id/users/user-id/sessions/session-id/wipe
```

Or use the batch operation:

```json
{
    "method": "users/sessions/wipe",
    "user_id": "...",
    "session_id: "..."
}
```

The response code is 204 if successful.

#### Re-authenticate session

This disables the session, requiring the user to log in again. No data is deleted on the device.

API:

```
POST /api/v4/backend-deployment-id/users/user-id/sessions/session-id/re-authenticate
```

Or use the batch operation:

```json
{
    "method": "users/sessions/re-authenticate",
    "user_id": "...",
    "session_id: "..."
}
```

The response code is 204 if successful.

#### Generate Authentication Token

Generate a temporary token that can be used for enrollment.

<Warning>

Authentication tokens expire 5 minutes after being created.

</Warning>

If the "multiple devices per user" flag is not enabled for the application, this can only be used to enroll one user at a time.

API:

```
POST /api/v4/backend-deployment-id/users/user-id/authentication-token
```

Or use the batch operation:

```json
{
    "method": "users/authentication-token",
    "user_id": "..."
}
```

Sample Response:

```json
{
    "token": "12345678",
    "url": "https://embark.mobi/enroll?h=internal-testing.journeyapps.com&k=12345678&t=j"
}
```
