# Azion CLI device-group

The Azion CLI `device-group` commands create, list, describe, update, and delete [device groups](/en/documentation/platform/applications/device-groups/), the names and regular expressions an application compares with the `User-Agent` header of each request. A device group belongs to one application, so every command takes the `--application-id` of that application. The options every command accepts, such as `--format`, `--out`, and `-y`, are on [Global options](/en/documentation/devtools/cli/globals/).

---

## Create

`azion create device-group` creates a device group in an application, with the name and the regular expression you pass:

```bash
azion create device-group [flags]
```

| Flag               | Short | Type   | Default | Description                                                                                                                                                       |
| ------------------ | ----- | ------ | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--application-id` | —     | int    | —       | ID of the application that holds the device group.                                                                                                                |
| `--file`           | —     | string | —       | Path to a JSON file with the attributes of the device group. Use `-` to read the JSON from standard input.                                                        |
| `--name`           | —     | string | —       | Name of the device group. It takes letters and digits only.                                                                                                       |
| `--user-agent`     | —     | string | —       | **Required** unless `--file` is set. Regular expression to compare with the `User-Agent` header of each request. Without it, the command asks for the expression. |

The command needs Application Accelerator turned on for the application. While it is off, the command fails with this error:

```text
Error: Failed to create the device group: You do not have the permissions to access the API. Make sure the feature is enabled in your profile. Check your settings and try again. If the error persists, contact Azion support.
```

This command turns on Application Accelerator for the application with ID `1234567890`. The `--application-accelerator` flag is on [Azion CLI application](/en/documentation/devtools/cli/resources/application/):

```bash
azion update application --application-id 1234567890 --application-accelerator true
```

The command prints the ID of the updated application:

```text
Updated Application with ID 1234567890
```

A name with a hyphen or an underscore is refused with this error:

```text
Error: Failed to create the device group: ["Invalid device group name."]. Check your settings and try again. If the error persists, contact Azion support.
```

This command creates a device group named `mobile` that matches Android devices and devices whose header contains `Mobile`:

```bash
azion create device-group --application-id 1234567890 --name mobile --user-agent '(Mobile|Android)'
```

The command prints the ID of the device group:

```text
Created device group with ID 1238
```

---

## List

`azion list device-group` lists the device groups of one application, 50 to a page:

```bash
azion list device-group [flags]
```

| Flag               | Short | Type   | Default | Description                                                                               |
| ------------------ | ----- | ------ | ------- | ----------------------------------------------------------------------------------------- |
| `--application-id` | —     | int    | —       | ID of the application whose device groups you list.                                       |
| `--details`        | —     | —      | —       | Accepted, but adds no columns: the list keeps the `ID`, `NAME`, and `USER AGENT` columns. |
| `--filter`         | —     | string | —       | Name to filter the list by.                                                               |
| `--order-by`       | —     | string | —       | Field to sort the list by.                                                                |
| `--page`           | —     | int    | `1`     | Number of the page to return.                                                             |
| `--page-size`      | —     | int    | `50`    | Number of device groups on each page.                                                     |

This command lists the device groups of the application with ID `1234567890`:

```bash
azion list device-group --application-id 1234567890
```

The command prints one row per device group:

```text
ID    NAME     USER AGENT
1238  mobile   (Mobile|Android)
1239  tablet   (iPad|Tablet)
1240  mobile7  Mobile
```

---

## Describe

`azion describe device-group` prints the settings of one device group:

```bash
azion describe device-group [flags]
```

| Flag               | Short | Type | Default | Description                                                      |
| ------------------ | ----- | ---- | ------- | ---------------------------------------------------------------- |
| `--application-id` | —     | int  | —       | **Required**. ID of the application that holds the device group. |
| `--group-id`       | —     | int  | —       | **Required**. ID of the device group to describe.                |

This command describes the device group with ID `1238`:

```bash
azion describe device-group --application-id 1234567890 --group-id 1238
```

The command prints the ID, the name, and the regular expression of the device group:

```text
ID:           1238
Name:         mobile
User Agent:   (Mobile|Android)
```

With `--format json`, the command prints the full object: `created_at`, `id`, `name`, and `user_agent`.

---

## Update

`azion update device-group` changes the name or the regular expression of a device group:

```bash
azion update device-group [flags]
```

| Flag               | Short | Type   | Default | Description                                                                                      |
| ------------------ | ----- | ------ | ------- | ------------------------------------------------------------------------------------------------ |
| `--application-id` | —     | int    | —       | **Required**. ID of the application that holds the device group.                                 |
| `--file`           | —     | string | —       | Path to a JSON file with the attributes to change. Use `-` to read the JSON from standard input. |
| `--group-id`       | —     | int    | —       | **Required**. ID of the device group to update.                                                  |
| `--name`           | —     | string | —       | New name of the device group.                                                                    |
| `--user-agent`     | —     | string | —       | New regular expression to compare with the `User-Agent` header.                                  |

This command adds iPhone devices to the regular expression of the device group with ID `1238`:

```bash
azion update device-group --application-id 1234567890 --group-id 1238 --user-agent '(Mobile|Android|iPhone)'
```

The command prints the ID of the updated device group:

```text
Device Group 1238 was updated
```

---

## Delete

`azion delete device-group` deletes a device group from an application:

```bash
azion delete device-group [flags]
```

| Flag               | Short | Type | Default | Description                                                      |
| ------------------ | ----- | ---- | ------- | ---------------------------------------------------------------- |
| `--application-id` | —     | int  | —       | **Required**. ID of the application that holds the device group. |
| `--group-id`       | —     | int  | —       | **Required**. ID of the device group to delete.                  |

This command deletes the device group with ID `1239`:

```bash
azion delete device-group --application-id 1234567890 --group-id 1239 -y
```

The command confirms the deletion:

```text
Device group 1239 was successfully deleted
```

---

## Use a JSON file

`azion create device-group` and `azion update device-group` read the attributes of the device group from a JSON file with `--file`. The file carries `name` and `user_agent`.

This file creates a device group named `tablet` that matches iPad and tablet devices:

```json
{
  "name": "tablet",
  "user_agent": "(iPad|Tablet)"
}
```

Pass the file to the create command with the ID of the application:

```bash
azion create device-group --application-id 1234567890 --file dg-create.json
```

The command prints the ID of the device group:

```text
Created device group with ID 1239
```

This file renames a device group to `tabletupdated`:

```json
{
  "name": "tabletupdated"
}
```

Pass the file to the update command with the IDs of the application and the device group:

```bash
azion update device-group --application-id 1234567890 --group-id 1239 --file dg-update.json
```

The command prints the ID of the updated device group:

```text
Device Group 1239 was updated
```

A field the file leaves out keeps its value. After this update, the device group with ID `1239` still has `(iPad|Tablet)` as its `user_agent`.

---

## Related resources

- [Global options](/en/documentation/devtools/cli/globals.md): The options every command accepts, such as `--format`, `--out`, and `-y`.
- [Device Groups](/en/documentation/platform/applications/device-groups.md): How an application matches the `User-Agent` header with a device group, and in which order.
- [Azion CLI application](/en/documentation/devtools/cli/resources/application.md): The commands that create an application and turn on Application Accelerator for it.
- [Azion CLI rules-engine](/en/documentation/devtools/cli/resources/rules-engine.md): The commands that create the rules that act on a device group.
