# Applications

The `azion/applications` module is the Azion Lib library for [Applications](/en/documentation/platform/applications/). Its functions create, list, read, update, and delete applications. Inside an application, they manage its [origins](/en/documentation/platform/connectors/origins/), [cache settings](/en/documentation/platform/applications/cache/cache-settings/), [device groups](/en/documentation/platform/applications/device-groups/), [function instances](/en/documentation/platform/applications/functions-instances/), and [rules](/en/documentation/platform/applications/rules-engine/). The module calls Azion API v3, and each function takes one object argument.

Install the package:

```bash
npm install azion
```

The `azion` package receives bug fixes only, and its maintenance ends in December 2026.

The samples on this page are ES modules that use top-level `await`, and they run in Node.js. Most of them are TypeScript. A sample whose payload TypeScript rejects is JavaScript, and its section names the type that rejects it.

---

## Authentication

Functions that you import and call directly read your [personal token](/en/documentation/fundamentals/personal-tokens/) from the `AZION_TOKEN` environment variable. A client from [createAzionApplicationClient](#createazionapplicationclient) carries the token in its `token` field.

| Variable      | Description                       |
| ------------- | --------------------------------- |
| `AZION_TOKEN` | Your Azion personal token.        |
| `AZION_DEBUG` | With `true`, turns on debug mode. |

For more information, refer to [How Azion Lib works](/en/documentation/devtools/azion-lib/how-it-works/).

---

## Response envelope

The `azion/applications` functions report a failure in one of two ways, depending on the object they act on:

- The application-level functions [createApplication](#createapplication), [getApplications](#getapplications), [getApplication](#getapplication), [patchApplication](#patchapplication), and [putApplication](#putapplication) return `{ data }` on success. When the API answers with an error status, they throw `Error: HTTP error! Status: <code> - <TEXT>`, so call them inside `try`/`catch`.
- [deleteApplication](#deleteapplication) and the functions for origins, cache settings, device groups, function instances, and rules do not throw. They return an [AzionApplicationResponse](#azionapplicationresponse), `{ data?, error? }`. On failure, `error` holds `{ message, operation }`, where `operation` names the call, such as `get origin`.

The samples for the application-level functions destructure `error` as well. On a failed request, those functions throw before the sample checks it.

A delete that succeeds still returns `{ error: { message: 'Expected JSON response, but got: ', operation } }`. The API answers a delete with an empty body, which the module reads as an error. The envelope cannot tell a successful delete from a failed one, so each delete sample on this page reads the object back. A `404` answer confirms the delete.

---

## Functions by resource

The module groups its functions by the object they manage. An application is addressed by `applicationId`, which every function except `createApplication` and `getApplications` takes. Rules also take a `phase`, and an origin is addressed by its `originKey`, a UUID.

| Resource          | Functions                                                                                                                                                                                                                                           |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Application       | [createApplication](#createapplication), [getApplications](#getapplications), [getApplication](#getapplication), [patchApplication](#patchapplication), [putApplication](#putapplication), [deleteApplication](#deleteapplication)                  |
| Origin            | [createOrigin](#createorigin), [getOrigins](#getorigins), [getOrigin](#getorigin), [updateOrigin](#updateorigin), [deleteOrigin](#deleteorigin)                                                                                                     |
| Cache setting     | [createCacheSetting](#createcachesetting), [getCacheSettings](#getcachesettings), [getCacheSetting](#getcachesetting), [updateCacheSetting](#updatecachesetting), [deleteCacheSetting](#deletecachesetting)                                         |
| Device group      | [createDeviceGroup](#createdevicegroup), [getDeviceGroups](#getdevicegroups), [getDeviceGroup](#getdevicegroup), [updateDeviceGroup](#updatedevicegroup), [deleteDeviceGroup](#deletedevicegroup)                                                   |
| Function instance | [createFunctionInstance](#createfunctioninstance), [getFunctionInstances](#getfunctioninstances), [getFunctionInstance](#getfunctioninstance), [updateFunctionInstance](#updatefunctioninstance), [deleteFunctionInstance](#deletefunctioninstance) |
| Rule              | [createRule](#createrule), [getRules](#getrules), [getRule](#getrule), [updateRule](#updaterule), [deleteRule](#deleterule)                                                                                                                         |

An application that [createApplication](#createapplication) or [getApplication](#getapplication) returns also carries the functions of the five sub-resources as [application methods](#application-methods).

---

## createAzionApplicationClient

Creates a client that holds a token and exposes the six application-level functions as methods. `createAzionApplicationClient` is also the default export of the module. In TypeScript with `moduleResolution` set to `nodenext`, the default import is not callable, so import the named export. With `moduleResolution` set to `bundler`, both imports type-check.

```typescript
function createAzionApplicationClient(config?: Partial<{
  token: string;
  options?: AzionClientOptions;
}>): AzionApplicationsClient;
```

| Parameter | Type                                        | Required | Description                                                        |
| --------- | ------------------------------------------- | -------- | ------------------------------------------------------------------ |
| `token`   | `string`                                    | No       | Your Azion personal token.                                         |
| `options` | [`AzionClientOptions`](#azionclientoptions) | No       | Request options. No sample on this page passes them to the client. |

Returns an [AzionApplicationsClient](#azionapplicationsclient). Its methods take the same object as the matching function on this page. The client has no methods for origins, cache settings, device groups, function instances, or rules: call those functions directly, or use the [application methods](#application-methods).

This sample creates a client and prints its methods:

```typescript
import { createAzionApplicationClient } from 'azion/applications';

const client = createAzionApplicationClient({
  token: process.env.AZION_TOKEN,
});
console.log('client methods:', Object.keys(client));
```

Output:

```text
client methods: [
  'createApplication',
  'deleteApplication',
  'getApplication',
  'getApplications',
  'putApplication',
  'patchApplication'
]
```

---

## createApplication

Creates an application.

```typescript
function createApplication(params: {
  data: ApiCreateApplicationPayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionApplication>>;
```

| Parameter | Type                                                      | Required | Description                                          |
| --------- | --------------------------------------------------------- | -------- | ---------------------------------------------------- |
| `data`    | [`ApiBaseApplicationPayload`](#apibaseapplicationpayload) | Yes      | The settings of the application. `name` is required. |
| `options` | [`AzionClientOptions`](#azionclientoptions)               | No       | Request options.                                     |

Returns `data` as the created [AzionApplication](#azionapplication), with the `id` the API assigned. On an error status, the function throws.

The type declares `application_acceleration`, but API v3 refuses it in a create request as an unknown field. With it, the function throws `Error: HTTP error! Status: 400 - BAD REQUEST`, so leave it out.

This sample is JavaScript, because TypeScript rejects the string `'http,https'` for `delivery_protocol`, whose type is the `DeliveryProtocol` enum:

```javascript
import { createApplication } from 'azion/applications';

// Create a new application
const { data: newApp, error } = await createApplication({
  data: {
    name: 'my-app',
    delivery_protocol: 'http,https',
  },
});
if (newApp) {
  console.log(`Application created: ${newApp.id} (${newApp.name}, ${newApp.delivery_protocol})`);
} else {
  console.error('Error creating application:', error);
}
```

Output:

```text
Application created: 1234567890 (my-app, http,https)
```

---

## getApplications

Lists the applications of the account, one page at a time.

```typescript
function getApplications(params?: {
  params?: ApiListApplicationsParams;
  options?: AzionClientOptions;
}): Promise<AzionApplicationCollectionResponse<AzionApplication>>;
```

| Parameter | Type                                                      | Required | Description                                                                                                                    |
| --------- | --------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `params`  | [`ApiListApplicationsParams`](#apilistapplicationsparams) | No       | Pagination: `page` and `page_size`. Without ordering keys, the function asks for the list ordered by name, in ascending order. |
| `options` | [`AzionClientOptions`](#azionclientoptions)               | No       | Request options.                                                                                                               |

Returns an [AzionApplicationCollectionResponse](#azionapplicationcollectionresponse): `data.results` holds the page, and `data.count` holds the number of applications in the account. On an error status, the function throws.

```typescript
import { getApplications } from 'azion/applications';

// List all applications
const { data: apps, error } = await getApplications({
  params: { page: 1, page_size: 20 },
});
if (apps) {
  console.log(`Found ${apps.count} applications; this page has ${apps.results.length}`);
} else {
  console.error('Error listing applications:', error);
}
```

Output:

```text
Found 22 applications; this page has 20
```

---

## getApplication

Returns one application by its ID.

```typescript
function getApplication(params: {
  applicationId: number;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionApplication>>;
```

| Parameter       | Type                                        | Required | Description                |
| --------------- | ------------------------------------------- | -------- | -------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.           |

Returns `data` as an [AzionApplication](#azionapplication) that carries the [application methods](#application-methods). An ID that matches no application makes the function throw `Error: HTTP error! Status: 404 - NOT FOUND`.

```typescript
import { getApplication } from 'azion/applications';

// Retrieve a specific application
const applicationId = 1234567890; // Replace with the actual application ID

const { data: app, error } = await getApplication({ applicationId });

if (error) {
  console.error('Error retrieving application:', error);
} else {
  console.log('Application details:', app?.id, app?.name, app?.delivery_protocol, app?.active);
}
```

Output:

```text
Application details: 1234567890 my-app http,https true
```

---

## patchApplication

Sends the application fields you pass in a `PATCH` request. Use it to rename an application or to change one setting, such as `edge_functions: true`, which [createFunctionInstance](#createfunctioninstance) requires.

```typescript
function patchApplication(params: {
  applicationId: number;
  data: Partial<ApiUpdateApplicationPayload>;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionApplication>>;
```

| Parameter       | Type                                                        | Required | Description                                    |
| --------------- | ----------------------------------------------------------- | -------- | ---------------------------------------------- |
| `applicationId` | `number`                                                    | Yes      | The ID of the application to update.           |
| `data`          | [`ApiUpdateApplicationPayload`](#apibaseapplicationpayload) | Yes      | The fields to change. Every field is optional. |
| `options`       | [`AzionClientOptions`](#azionclientoptions)                 | No       | Request options.                               |

Returns `data` as the updated [AzionApplication](#azionapplication). On an error status, the function throws.

```typescript
import { patchApplication } from 'azion/applications';

// Update some fields of an existing application
const applicationId = 1234567890; // Replace with the actual application ID

const { data: updatedApp, error } = await patchApplication({
  applicationId,
  data: { name: 'my-app-patched' },
});

if (error) {
  console.error('Error updating application:', error);
} else {
  console.log('Updated application:', updatedApp?.id, updatedApp?.name);
}
```

Output:

```text
Updated application: 1234567890 my-app-patched
```

---

## putApplication

Sends the application settings you pass in a `PUT` request.

```typescript
function putApplication(params: {
  applicationId: number;
  data: ApiUpdateApplicationPayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionApplication>>;
```

| Parameter       | Type                                                        | Required | Description                          |
| --------------- | ----------------------------------------------------------- | -------- | ------------------------------------ |
| `applicationId` | `number`                                                    | Yes      | The ID of the application to update. |
| `data`          | [`ApiUpdateApplicationPayload`](#apibaseapplicationpayload) | Yes      | The settings of the application.     |
| `options`       | [`AzionClientOptions`](#azionclientoptions)                 | No       | Request options.                     |

Returns `data` as the updated [AzionApplication](#azionapplication). On an error status, the function throws.

API v3 can refuse a `delivery_protocol` value that the type allows. For example, the API can answer `delivery_protocol: 'https'` with `"https" is not a valid choice.`, and the function then throws.

This sample is JavaScript, because TypeScript rejects the string `'http'` for `delivery_protocol`, whose type is the `DeliveryProtocol` enum:

```javascript
import { putApplication } from 'azion/applications';

// Replace the settings of an existing application
const applicationId = 1234567890; // Replace with the actual application ID

const { data: updatedApp, error } = await putApplication({
  applicationId,
  data: {
    name: 'my-app',
    delivery_protocol: 'http',
  },
});

if (error) {
  console.error('Error updating application:', error);
} else {
  console.log('Updated application:', updatedApp.id, updatedApp.name, updatedApp.delivery_protocol);
}
```

Output:

```text
Updated application: 1234567890 my-app http
```

---

## deleteApplication

Deletes an application by its ID.

```typescript
function deleteApplication(params: {
  applicationId: number;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<void>>;
```

| Parameter       | Type                                        | Required | Description                          |
| --------------- | ------------------------------------------- | -------- | ------------------------------------ |
| `applicationId` | `number`                                    | Yes      | The ID of the application to delete. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                     |

Unlike the other application-level functions, `deleteApplication` returns an envelope and does not throw. A successful delete returns `error` with the message `Expected JSON response, but got: `, so the sample confirms the delete with [getApplication](#getapplication), which throws a 404 error for an application that no longer exists.

```typescript
import { deleteApplication, getApplication } from 'azion/applications';

// Delete an existing application
const applicationId = 1234567890; // Replace with the actual application ID

const { error: deleteError } = await deleteApplication({ applicationId });

// On success (HTTP 204) the envelope still carries an error, so confirm by reading it back;
// getApplication throws when the application does not exist
try {
  await getApplication({ applicationId });
  console.error('Error deleting application:', deleteError);
} catch (err) {
  console.log(`Application ${applicationId} deleted (read back: ${(err as Error).message})`);
}
```

Output:

```text
Application 1234567890 deleted (read back: HTTP error! Status: 404 - NOT FOUND)
```

---

## createOrigin

Creates an origin in an application. An origin is the server the application retrieves content from.

```typescript
function createOrigin(params: {
  applicationId: number;
  data: ApiCreateOriginPayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionOrigin>>;
```

| Parameter       | Type                                        | Required | Description                                                                                        |
| --------------- | ------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.                                                                         |
| `data`          | [`ApiCreateOriginPayload`](#azionorigin)    | Yes      | The settings of the origin. The sample sets `name`, `origin_type`, `addresses`, and `host_header`. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                                                                                   |

Returns `data` as the created [AzionOrigin](#azionorigin). The API identifies an origin by its `origin_key`, a UUID, which the other origin functions take as `originKey`.

This sample is JavaScript, because `ApiCreateOriginPayload` requires every origin field, including `origin_key` and the HMAC fields, and types `origin_type` as an enum:

```javascript
import { createOrigin } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

// Define the data for the new origin
const newOriginData = {
  name: 'my-origin',
  origin_type: 'single_origin',
  addresses: [{ address: 'example.com' }],
  host_header: '${host}',
};

// Create a new origin
const { data: newOrigin, error } = await createOrigin({ applicationId, data: newOriginData });

if (error) {
  console.error('Error creating origin:', error);
} else {
  console.log('Created origin:', newOrigin.origin_key, newOrigin.name, newOrigin.addresses);
}
```

Output:

```text
Created origin: 11111111-1111-1111-1111-111111111111 my-origin [
  {
    address: 'example.com',
    weight: null,
    server_role: 'primary',
    is_active: true
  }
]
```

---

## getOrigins

Lists the origins of an application, one page at a time.

```typescript
function getOrigins(params: {
  applicationId: number;
  params?: ApiListOriginsParams;
  options?: AzionClientOptions;
}): Promise<AzionApplicationCollectionResponse<AzionOrigin>>;
```

| Parameter       | Type                                        | Required | Description                         |
| --------------- | ------------------------------------------- | -------- | ----------------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.          |
| `params`        | [`ApiListOriginsParams`](#list-parameters)  | No       | Pagination: `page` and `page_size`. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                    |

Returns an [AzionApplicationCollectionResponse](#azionapplicationcollectionresponse) whose `data.results` holds [AzionOrigin](#azionorigin) objects.

```typescript
import { getOrigins } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

const { data: origins, error } = await getOrigins({ applicationId, params: { page: 1, page_size: 10 } });

if (error) {
  console.error('Error listing origins:', error);
} else {
  console.log(`Found ${origins?.count} origins:`, origins?.results.map((o) => `${o.name} (${o.origin_key})`));
}
```

Output:

```text
Found 1 origins: [ 'my-origin (11111111-1111-1111-1111-111111111111)' ]
```

---

## getOrigin

Returns one origin of an application by its origin key.

```typescript
function getOrigin(params: {
  applicationId: number;
  originKey: string;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionOrigin>>;
```

| Parameter       | Type                                        | Required | Description                             |
| --------------- | ------------------------------------------- | -------- | --------------------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.              |
| `originKey`     | `string`                                    | Yes      | The `origin_key` of the origin, a UUID. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                        |

Returns `data` as an [AzionOrigin](#azionorigin). A key that matches no origin returns `error` with the message `HTTP error! Status: 404 - NOT FOUND` and the operation `get origin`.

```typescript
import { getOrigin } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const originKey = '11111111-1111-1111-1111-111111111111'; // Replace with the origin key (a UUID)

const { data: origin, error } = await getOrigin({ applicationId, originKey });

if (error) {
  console.error('Error retrieving origin:', error);
} else {
  console.log('Origin details:', origin?.origin_key, origin?.name, origin?.origin_type, origin?.host_header);
}
```

Output:

```text
Origin details: 11111111-1111-1111-1111-111111111111 my-origin single_origin ${host}
```

---

## updateOrigin

Sends the origin fields you pass in a `PATCH` request.

```typescript
function updateOrigin(params: {
  applicationId: number;
  originKey: string;
  data: ApiUpdateOriginRequest;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionOrigin>>;
```

| Parameter       | Type                                        | Required | Description                               |
| --------------- | ------------------------------------------- | -------- | ----------------------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.                |
| `originKey`     | `string`                                    | Yes      | The `origin_key` of the origin to update. |
| `data`          | [`ApiUpdateOriginRequest`](#azionorigin)    | Yes      | The fields to change.                     |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                          |

Returns `data` as the updated [AzionOrigin](#azionorigin).

This sample is JavaScript, because `ApiUpdateOriginRequest` requires an `id`, which the request does not need:

```javascript
import { updateOrigin } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const originKey = '11111111-1111-1111-1111-111111111111'; // Replace with the origin key (a UUID)

const { data: updatedOrigin, error } = await updateOrigin({
  applicationId,
  originKey,
  data: { name: 'my-origin-updated' },
});

if (error) {
  console.error('Error updating origin:', error);
} else {
  console.log('Updated origin:', updatedOrigin.origin_key, updatedOrigin.name);
}
```

Output:

```text
Updated origin: 11111111-1111-1111-1111-111111111111 my-origin-updated
```

---

## deleteOrigin

Deletes an origin of an application by its origin key.

```typescript
function deleteOrigin(params: {
  applicationId: number;
  originKey: string;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<void>>;
```

| Parameter       | Type                                        | Required | Description                               |
| --------------- | ------------------------------------------- | -------- | ----------------------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.                |
| `originKey`     | `string`                                    | Yes      | The `origin_key` of the origin to delete. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                          |

A successful delete returns `error` with the message `Expected JSON response, but got: `, so the sample reads the origin back with [getOrigin](#getorigin). A `404` error confirms the delete.

```typescript
import { deleteOrigin, getOrigin } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const originKey = '11111111-1111-1111-1111-111111111111'; // Replace with the origin key (a UUID)

const { error: deleteError } = await deleteOrigin({ applicationId, originKey });

// On success (HTTP 204) the envelope still carries an error, so confirm by reading the origin back
const { error } = await getOrigin({ applicationId, originKey });
if (error) {
  console.log(`Origin ${originKey} deleted (read back: ${error.message})`);
} else {
  console.error('Error deleting origin:', deleteError);
}
```

Output:

```text
Origin 11111111-1111-1111-1111-111111111111 deleted (read back: HTTP error! Status: 404 - NOT FOUND)
```

---

## createCacheSetting

Creates a cache setting in an application. The application must have an origin first. On an application with none, the API refuses the cache setting, and the function returns `error` with the message `HTTP error! Status: 400 - BAD REQUEST`.

```typescript
function createCacheSetting(params: {
  applicationId: number;
  data: ApiBaseCacheSettingPayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionCacheSetting>>;
```

| Parameter       | Type                                                        | Required | Description                                            |
| --------------- | ----------------------------------------------------------- | -------- | ------------------------------------------------------ |
| `applicationId` | `number`                                                    | Yes      | The ID of the application.                             |
| `data`          | [`ApiBaseCacheSettingPayload`](#apibasecachesettingpayload) | Yes      | The settings of the cache setting. `name` is required. |
| `options`       | [`AzionClientOptions`](#azionclientoptions)                 | No       | Request options.                                       |

`browser_cache_settings` takes `honor`, `override`, or `ignore`, and `cdn_cache_settings` takes `honor` or `override`. With `override`, the sample also sets the matching maximum TTL field, `browser_cache_settings_maximum_ttl` or `cdn_cache_settings_maximum_ttl`.

Returns `data` as the created [AzionCacheSetting](#azioncachesetting), with its `id`.

This sample is JavaScript, because TypeScript rejects string values for `browser_cache_settings` and `cdn_cache_settings`, whose types are enums the module does not export:

```javascript
import { createCacheSetting } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

// Create a new cache setting
const cacheSettingData = {
  name: 'my-cache-setting',
  browser_cache_settings: 'override',
  browser_cache_settings_maximum_ttl: 3600,
  cdn_cache_settings: 'override',
  cdn_cache_settings_maximum_ttl: 7200,
};

const { data: newCacheSetting, error } = await createCacheSetting({ applicationId, data: cacheSettingData });

if (error) {
  console.error('Error creating cache setting:', error);
} else {
  console.log('Cache setting created successfully:', newCacheSetting.id, newCacheSetting.name, newCacheSetting.cdn_cache_settings_maximum_ttl);
}
```

Output:

```text
Cache setting created successfully: 234567 my-cache-setting 7200
```

---

## getCacheSettings

Lists the cache settings of an application, one page at a time.

```typescript
function getCacheSettings(params: {
  applicationId: number;
  params?: ApiListCacheSettingsParams;
  options?: AzionClientOptions;
}): Promise<AzionApplicationCollectionResponse<AzionCacheSetting>>;
```

| Parameter       | Type                                             | Required | Description                                                                                                                               |
| --------------- | ------------------------------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `applicationId` | `number`                                         | Yes      | The ID of the application.                                                                                                                |
| `params`        | [`ApiListCacheSettingsParams`](#list-parameters) | No       | Pagination: `page` and `page_size`. Leave out `sort` and `order`: the API refuses the values the type declares for them with a 400 error. |
| `options`       | [`AzionClientOptions`](#azionclientoptions)      | No       | Request options.                                                                                                                          |

Returns an [AzionApplicationCollectionResponse](#azionapplicationcollectionresponse) whose `data.results` holds [AzionCacheSetting](#azioncachesetting) objects.

```typescript
import { getCacheSettings } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

const { data: cacheSettings, error } = await getCacheSettings({
  applicationId,
  params: { page: 1, page_size: 20 },
});

if (error) {
  console.error('Error listing cache settings:', error);
} else {
  console.log(`Found ${cacheSettings?.count} cache settings:`, cacheSettings?.results.map((c) => `${c.id} ${c.name}`));
}
```

Output:

```text
Found 1 cache settings: [ '234568 my-other-cache-setting' ]
```

---

## getCacheSetting

Returns one cache setting of an application by its ID.

```typescript
function getCacheSetting(params: {
  applicationId: number;
  cacheSettingId: number;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionCacheSetting>>;
```

| Parameter        | Type                                        | Required | Description                  |
| ---------------- | ------------------------------------------- | -------- | ---------------------------- |
| `applicationId`  | `number`                                    | Yes      | The ID of the application.   |
| `cacheSettingId` | `number`                                    | Yes      | The ID of the cache setting. |
| `options`        | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.             |

Returns `data` as an [AzionCacheSetting](#azioncachesetting).

```typescript
import { getCacheSetting } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const cacheSettingId = 234567; // Replace with the actual cache setting ID

const { data: cacheSetting, error } = await getCacheSetting({ applicationId, cacheSettingId });

if (error) {
  console.error('Error retrieving cache setting:', error);
} else {
  console.log('Cache setting details:', cacheSetting?.id, cacheSetting?.name, cacheSetting?.browser_cache_settings, cacheSetting?.cdn_cache_settings);
}
```

Output:

```text
Cache setting details: 234567 my-cache-setting override override
```

---

## updateCacheSetting

Sends the cache setting fields you pass in a `PATCH` request.

```typescript
function updateCacheSetting(params: {
  applicationId: number;
  cacheSettingId: number;
  data: ApiUpdateCacheSettingPayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionCacheSetting>>;
```

| Parameter        | Type                                                          | Required | Description                                    |
| ---------------- | ------------------------------------------------------------- | -------- | ---------------------------------------------- |
| `applicationId`  | `number`                                                      | Yes      | The ID of the application.                     |
| `cacheSettingId` | `number`                                                      | Yes      | The ID of the cache setting to update.         |
| `data`           | [`ApiUpdateCacheSettingPayload`](#apibasecachesettingpayload) | Yes      | The fields to change. Every field is optional. |
| `options`        | [`AzionClientOptions`](#azionclientoptions)                   | No       | Request options.                               |

Returns `data` as the updated [AzionCacheSetting](#azioncachesetting). A payload without enum fields, such as `name` and a TTL, type-checks in TypeScript.

```typescript
import { updateCacheSetting } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const cacheSettingId = 234567; // Replace with the actual cache setting ID

const { data: updatedCacheSetting, error } = await updateCacheSetting({
  applicationId,
  cacheSettingId,
  data: { name: 'my-cache-setting-updated', cdn_cache_settings_maximum_ttl: 3600 },
});

if (error) {
  console.error('Error updating cache setting:', error);
} else {
  console.log('Cache setting updated:', updatedCacheSetting?.name, updatedCacheSetting?.cdn_cache_settings_maximum_ttl);
}
```

Output:

```text
Cache setting updated: my-cache-setting-updated 3600
```

---

## deleteCacheSetting

Deletes a cache setting of an application by its ID.

```typescript
function deleteCacheSetting(params: {
  applicationId: number;
  cacheSettingId: number;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<void>>;
```

| Parameter        | Type                                        | Required | Description                            |
| ---------------- | ------------------------------------------- | -------- | -------------------------------------- |
| `applicationId`  | `number`                                    | Yes      | The ID of the application.             |
| `cacheSettingId` | `number`                                    | Yes      | The ID of the cache setting to delete. |
| `options`        | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                       |

A successful delete returns `error` with the message `Expected JSON response, but got: `, so the sample reads the cache setting back with [getCacheSetting](#getcachesetting). A `404` error confirms the delete.

```typescript
import { deleteCacheSetting, getCacheSetting } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const cacheSettingId = 234567; // Replace with the actual cache setting ID

const { error: deleteError } = await deleteCacheSetting({ applicationId, cacheSettingId });

// On success (HTTP 204) the envelope still carries an error, so confirm by reading it back
const { error } = await getCacheSetting({ applicationId, cacheSettingId });
if (error) {
  console.log(`Cache setting ${cacheSettingId} deleted (read back: ${error.message})`);
} else {
  console.error('Error deleting cache setting:', deleteError);
}
```

Output:

```text
Cache setting 234567 deleted (read back: HTTP error! Status: 404 - NOT FOUND)
```

---

## createDeviceGroup

Creates a device group in an application. A device group matches devices by a regular expression that the platform compares with the `User-Agent` request header.

```typescript
function createDeviceGroup(params: {
  applicationId: number;
  data: ApiCreateDeviceGroupPayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionDeviceGroup>>;
```

| Parameter       | Type                                        | Required | Description                                                                                               |
| --------------- | ------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.                                                                                |
| `data`          | `{ name: string; user_agent: string }`      | Yes      | `name` names the group, and `user_agent` holds the regular expression, such as `Mobile\|Android\|iPhone`. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                                                                                          |

Returns `data` as the created [AzionDeviceGroup](#aziondevicegroup). The API refuses a `name` that contains a space or a hyphen. The function then returns `error` with the message `HTTP error! Status: 400 - BAD REQUEST`.

```typescript
import { createDeviceGroup } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

// Create a new device group
const deviceGroupData = {
  name: 'MobileDevices',
  user_agent: 'Mobile|Android|iPhone',
};

const { data: newDeviceGroup, error } = await createDeviceGroup({ applicationId, data: deviceGroupData });

if (error) {
  console.error('Error creating device group:', error);
} else {
  console.log('Device group created successfully:', newDeviceGroup);
}
```

Output:

```text
Device group created successfully: {
  id: 1234,
  name: 'MobileDevices',
  user_agent: 'Mobile|Android|iPhone'
}
```

---

## getDeviceGroups

Lists the device groups of an application, one page at a time.

```typescript
function getDeviceGroups(params: {
  applicationId: number;
  params?: ApiListDeviceGroupsParams;
  options?: AzionClientOptions;
}): Promise<AzionApplicationCollectionResponse<AzionDeviceGroup>>;
```

| Parameter       | Type                                            | Required | Description                         |
| --------------- | ----------------------------------------------- | -------- | ----------------------------------- |
| `applicationId` | `number`                                        | Yes      | The ID of the application.          |
| `params`        | [`ApiListDeviceGroupsParams`](#list-parameters) | No       | Pagination: `page` and `page_size`. |
| `options`       | [`AzionClientOptions`](#azionclientoptions)     | No       | Request options.                    |

Returns an [AzionApplicationCollectionResponse](#azionapplicationcollectionresponse) whose `data.results` holds [AzionDeviceGroup](#aziondevicegroup) objects.

```typescript
import { getDeviceGroups } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

const { data: deviceGroups, error } = await getDeviceGroups({ applicationId, params: { page: 1, page_size: 20 } });

if (error) {
  console.error('Error listing device groups:', error);
} else {
  console.log(`Found ${deviceGroups?.count} device groups:`, deviceGroups?.results);
}
```

Output:

```text
Found 1 device groups: [
  {
    id: 1234,
    name: 'MobileDevices',
    user_agent: 'Mobile|Android|iPhone'
  }
]
```

---

## getDeviceGroup

Returns one device group of an application by its ID.

```typescript
function getDeviceGroup(params: {
  applicationId: number;
  deviceGroupId: number;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionDeviceGroup>>;
```

| Parameter       | Type                                        | Required | Description                 |
| --------------- | ------------------------------------------- | -------- | --------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.  |
| `deviceGroupId` | `number`                                    | Yes      | The ID of the device group. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.            |

Returns `data` as an [AzionDeviceGroup](#aziondevicegroup).

```typescript
import { getDeviceGroup } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const deviceGroupId = 1234; // Replace with the actual device group ID

const { data: deviceGroup, error } = await getDeviceGroup({ applicationId, deviceGroupId });

if (error) {
  console.error('Error retrieving device group:', error);
} else {
  console.log('Device group details:', deviceGroup);
}
```

Output:

```text
Device group details: {
  id: 1234,
  name: 'MobileDevices',
  user_agent: 'Mobile|Android|iPhone'
}
```

---

## updateDeviceGroup

Sends the device group fields you pass in a `PATCH` request. The new `name` follows the same rule as on create: no spaces and no hyphens.

```typescript
function updateDeviceGroup(params: {
  applicationId: number;
  deviceGroupId: number;
  data: ApiUpdateDeviceGroupPayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionDeviceGroup>>;
```

| Parameter       | Type                                        | Required | Description                           |
| --------------- | ------------------------------------------- | -------- | ------------------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.            |
| `deviceGroupId` | `number`                                    | Yes      | The ID of the device group to update. |
| `data`          | `{ name?: string; user_agent?: string }`    | Yes      | The fields to change.                 |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                      |

Returns `data` as the updated [AzionDeviceGroup](#aziondevicegroup).

```typescript
import { updateDeviceGroup } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const deviceGroupId = 1234; // Replace with the actual device group ID

const { data: updatedDeviceGroup, error } = await updateDeviceGroup({
  applicationId,
  deviceGroupId,
  data: { name: 'MobileAndTablets', user_agent: 'Mobile|Android|iPhone|iPad' },
});

if (error) {
  console.error('Error updating device group:', error);
} else {
  console.log('Device group updated:', updatedDeviceGroup);
}
```

Output:

```text
Device group updated: {
  id: 1234,
  name: 'MobileAndTablets',
  user_agent: 'Mobile|Android|iPhone|iPad'
}
```

---

## deleteDeviceGroup

Deletes a device group of an application by its ID.

```typescript
function deleteDeviceGroup(params: {
  applicationId: number;
  deviceGroupId: number;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<void>>;
```

| Parameter       | Type                                        | Required | Description                           |
| --------------- | ------------------------------------------- | -------- | ------------------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.            |
| `deviceGroupId` | `number`                                    | Yes      | The ID of the device group to delete. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                      |

A successful delete returns `error` with the message `Expected JSON response, but got: `, so the sample reads the device group back with [getDeviceGroup](#getdevicegroup). A `404` error confirms the delete.

```typescript
import { deleteDeviceGroup, getDeviceGroup } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const deviceGroupId = 1234; // Replace with the actual device group ID

const { error: deleteError } = await deleteDeviceGroup({ applicationId, deviceGroupId });

// On success (HTTP 204) the envelope still carries an error, so confirm by reading it back
const { error } = await getDeviceGroup({ applicationId, deviceGroupId });
if (error) {
  console.log(`Device group ${deviceGroupId} deleted (read back: ${error.message})`);
} else {
  console.error('Error deleting device group:', deleteError);
}
```

Output:

```text
Device group 1234 deleted (read back: HTTP error! Status: 404 - NOT FOUND)
```

---

## createFunctionInstance

Creates a function instance in an application. An instance runs an existing [function](/en/documentation/platform/functions/) for that application, with the arguments the instance sets.

Two things must exist first. The application must have functions turned on, which [patchApplication](#patchapplication) does with `data: { edge_functions: true }`. The function must exist too: the instance names it by its ID in `edge_function_id`, and the `azion` package has no module that creates functions.

```typescript
function createFunctionInstance(params: {
  applicationId: number;
  data: ApiCreateFunctionInstancePayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionFunctionInstance>>;
```

| Parameter       | Type                                                                    | Required | Description                                                                           |
| --------------- | ----------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------- |
| `applicationId` | `number`                                                                | Yes      | The ID of the application.                                                            |
| `data`          | [`ApiCreateFunctionInstancePayload`](#apicreatefunctioninstancepayload) | Yes      | `name`, the `edge_function_id` of the function, and the `args` the function receives. |
| `options`       | [`AzionClientOptions`](#azionclientoptions)                             | No       | Request options.                                                                      |

Returns `data` as the created [AzionFunctionInstance](#azionfunctioninstance), with its `id`.

```typescript
import { createFunctionInstance } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

// Define the data for the new function instance
const functionInstanceData = {
  name: 'my-function-instance',
  edge_function_id: 23456, // Replace with the ID of an existing function
  args: { greeting: 'hello' },
};

// Create a new function instance
const { data: newFunctionInstance, error } = await createFunctionInstance({ applicationId, data: functionInstanceData });

if (error) {
  console.error('Error creating function instance:', error);
} else {
  console.log('Function instance created successfully:', newFunctionInstance);
}
```

Output:

```text
Function instance created successfully: {
  edge_function_id: 23456,
  name: 'my-function-instance',
  args: { greeting: 'hello' },
  id: 12345
}
```

---

## getFunctionInstances

Lists the function instances of an application, one page at a time.

```typescript
function getFunctionInstances(params: {
  applicationId: number;
  params?: ApiListFunctionInstancesParams;
  options?: AzionClientOptions;
}): Promise<AzionApplicationCollectionResponse<AzionFunctionInstance>>;
```

| Parameter       | Type                                                 | Required | Description                         |
| --------------- | ---------------------------------------------------- | -------- | ----------------------------------- |
| `applicationId` | `number`                                             | Yes      | The ID of the application.          |
| `params`        | [`ApiListFunctionInstancesParams`](#list-parameters) | No       | Pagination: `page` and `page_size`. |
| `options`       | [`AzionClientOptions`](#azionclientoptions)          | No       | Request options.                    |

Returns an [AzionApplicationCollectionResponse](#azionapplicationcollectionresponse) whose `data.results` holds [AzionFunctionInstance](#azionfunctioninstance) objects.

```typescript
import { getFunctionInstances } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

const { data: functionInstances, error } = await getFunctionInstances({
  applicationId,
  params: { page: 1, page_size: 10 },
});

if (error) {
  console.error('Error listing function instances:', error);
} else {
  console.log(`Found ${functionInstances?.count} function instances:`, functionInstances?.results);
}
```

Output:

```text
Found 1 function instances: [
  {
    id: 12345,
    edge_function_id: 23456,
    name: 'my-function-instance',
    args: { greeting: 'hello' }
  }
]
```

---

## getFunctionInstance

Returns one function instance of an application by its ID.

```typescript
function getFunctionInstance(params: {
  applicationId: number;
  functionInstanceId: number;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionFunctionInstance>>;
```

| Parameter            | Type                                        | Required | Description                      |
| -------------------- | ------------------------------------------- | -------- | -------------------------------- |
| `applicationId`      | `number`                                    | Yes      | The ID of the application.       |
| `functionInstanceId` | `number`                                    | Yes      | The ID of the function instance. |
| `options`            | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                 |

Returns `data` as an [AzionFunctionInstance](#azionfunctioninstance).

```typescript
import { getFunctionInstance } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const functionInstanceId = 12345; // Replace with the actual function instance ID

const { data: functionInstance, error } = await getFunctionInstance({ applicationId, functionInstanceId });

if (error) {
  console.error('Error retrieving function instance:', error);
} else {
  console.log('Function instance details:', functionInstance);
}
```

Output:

```text
Function instance details: {
  id: 12345,
  edge_function_id: 23456,
  name: 'my-function-instance',
  args: { greeting: 'hello' }
}
```

---

## updateFunctionInstance

Sends the function instance fields you pass in a `PATCH` request.

```typescript
function updateFunctionInstance(params: {
  applicationId: number;
  functionInstanceId: number;
  data: ApiUpdateFunctionInstancePayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionFunctionInstance>>;
```

| Parameter            | Type                                                         | Required | Description                                      |
| -------------------- | ------------------------------------------------------------ | -------- | ------------------------------------------------ |
| `applicationId`      | `number`                                                     | Yes      | The ID of the application.                       |
| `functionInstanceId` | `number`                                                     | Yes      | The ID of the function instance to update.       |
| `data`               | [`ApiUpdateFunctionInstancePayload`](#azionfunctioninstance) | Yes      | The fields to change. The sample changes `name`. |
| `options`            | [`AzionClientOptions`](#azionclientoptions)                  | No       | Request options.                                 |

Returns `data` as the updated [AzionFunctionInstance](#azionfunctioninstance).

```typescript
import { updateFunctionInstance } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const functionInstanceId = 12345; // Replace with the actual function instance ID

const { data: updatedFunctionInstance, error } = await updateFunctionInstance({
  applicationId,
  functionInstanceId,
  data: { name: 'my-function-instance-updated' },
});

if (error) {
  console.error('Error updating function instance:', error);
} else {
  console.log('Function instance updated:', updatedFunctionInstance);
}
```

Output:

```text
Function instance updated: {
  id: 12345,
  edge_function_id: 23456,
  name: 'my-function-instance-updated',
  args: { greeting: 'hello' }
}
```

---

## deleteFunctionInstance

Deletes a function instance of an application by its ID.

```typescript
function deleteFunctionInstance(params: {
  applicationId: number;
  functionInstanceId: number;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<void>>;
```

| Parameter            | Type                                        | Required | Description                                |
| -------------------- | ------------------------------------------- | -------- | ------------------------------------------ |
| `applicationId`      | `number`                                    | Yes      | The ID of the application.                 |
| `functionInstanceId` | `number`                                    | Yes      | The ID of the function instance to delete. |
| `options`            | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                           |

A successful delete returns `error` with the message `Expected JSON response, but got: `, so the sample reads the instance back with [getFunctionInstance](#getfunctioninstance). A `404` error confirms the delete.

```typescript
import { deleteFunctionInstance, getFunctionInstance } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const functionInstanceId = 12345; // Replace with the actual function instance ID

const { error: deleteError } = await deleteFunctionInstance({ applicationId, functionInstanceId });

// On success (HTTP 204) the envelope still carries an error, so confirm by reading it back
const { error } = await getFunctionInstance({ applicationId, functionInstanceId });
if (error) {
  console.log(`Function instance ${functionInstanceId} deleted (read back: ${error.message})`);
} else {
  console.error('Error deleting function instance:', deleteError);
}
```

Output:

```text
Function instance 12345 deleted (read back: HTTP error! Status: 404 - NOT FOUND)
```

---

## createRule

Creates a rule of the Rules Engine of an application, in the request phase or the response phase.

```typescript
function createRule(params: {
  applicationId: number;
  phase: "request" | "response";
  data: ApiCreateRulePayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionRule>>;
```

| Parameter       | Type                                            | Required | Description                                             |
| --------------- | ----------------------------------------------- | -------- | ------------------------------------------------------- |
| `applicationId` | `number`                                        | Yes      | The ID of the application.                              |
| `phase`         | `'request' \| 'response'`                       | Yes      | The phase the rule runs in.                             |
| `data`          | [`ApiCreateRulePayload`](#apicreaterulepayload) | Yes      | The rule: `name`, `phase`, `criteria`, and `behaviors`. |
| `options`       | [`AzionClientOptions`](#azionclientoptions)     | No       | Request options.                                        |

`criteria` is a list of condition groups, and each group is a list of conditions with `variable`, `operator`, `conditional`, and `input_value`. `behaviors` lists the actions, each with a `name` and a `target`. For the variables, operators, and behavior names a rule can use, refer to [Rules Engine for Applications](/en/documentation/platform/applications/rules-engine/).

Returns `data` as the created [AzionRule](#azionrule), with its `id` and `order`. In the sample, `as const` keeps the literal types that `phase` and `conditional` need in TypeScript.

```typescript
import { createRule } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

// Define the data for the new rule
const ruleData = {
  name: 'Example Rule',
  phase: 'request' as const,
  criteria: [[{ variable: '${uri}', operator: 'starts_with', conditional: 'if' as const, input_value: '/example-path' }]],
  behaviors: [{ name: 'redirect_to_301', target: 'https://example.com' }],
};

// Create a new rule in the request phase
const { data: newRule, error } = await createRule({ applicationId, phase: 'request', data: ruleData });

if (error) {
  console.error('Error creating rule:', error);
} else {
  console.log('Created rule:', JSON.stringify(newRule));
}
```

Output:

```text
Created rule: {"id":123457,"name":"Example Rule","phase":"request","behaviors":[{"name":"redirect_to_301","target":"https://example.com"}],"criteria":[[{"variable":"${uri}","operator":"starts_with","conditional":"if","input_value":"/example-path"}]],"is_active":true,"order":1,"description":""}
```

---

## getRules

Lists the rules of one phase of an application, one page at a time.

```typescript
function getRules(params: {
  applicationId: number;
  phase: "request" | "response";
  params?: ApiListRulesParams;
  options?: AzionClientOptions;
}): Promise<AzionApplicationCollectionResponse<AzionRule>>;
```

| Parameter       | Type                                        | Required | Description                         |
| --------------- | ------------------------------------------- | -------- | ----------------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.          |
| `phase`         | `'request' \| 'response'`                   | Yes      | The phase to list.                  |
| `params`        | [`ApiListRulesParams`](#list-parameters)    | No       | Pagination: `page` and `page_size`. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.                    |

Returns an [AzionApplicationCollectionResponse](#azionapplicationcollectionresponse) whose `data.results` holds [AzionRule](#azionrule) objects. The `request` list also holds `Default Rule`, the rule in phase `default` that a new application already has.

```typescript
import { getRules } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

const { data: rules, error } = await getRules({ applicationId, phase: 'request', params: { page: 1, page_size: 10 } });

if (error) {
  console.error('Error listing rules:', error);
} else {
  console.log(`Found ${rules?.count} rules:`, rules?.results.map((r) => `${r.id} ${r.name} (${r.phase}, order ${r.order})`));
}
```

Output:

```text
Found 2 rules: [
  '123456 Default Rule (default, order 1)',
  '123457 Example Rule (request, order 1)'
]
```

---

## getRule

Returns one rule of an application by its phase and ID.

```typescript
function getRule(params: {
  applicationId: number;
  phase: "request" | "response";
  ruleId: number;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionRule>>;
```

| Parameter       | Type                                        | Required | Description                |
| --------------- | ------------------------------------------- | -------- | -------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application. |
| `phase`         | `'request' \| 'response'`                   | Yes      | The phase of the rule.     |
| `ruleId`        | `number`                                    | Yes      | The ID of the rule.        |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.           |

Returns `data` as an [AzionRule](#azionrule).

```typescript
import { getRule } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const ruleId = 123457; // Replace with the actual rule ID

const { data: rule, error } = await getRule({ applicationId, phase: 'request', ruleId });

if (error) {
  console.error('Error retrieving rule:', error);
} else {
  console.log('Rule details:', JSON.stringify(rule));
}
```

Output:

```text
Rule details: {"id":123457,"name":"Example Rule","phase":"request","behaviors":[{"name":"redirect_to_301","target":"https://example.com"}],"criteria":[[{"variable":"${uri}","operator":"starts_with","conditional":"if","input_value":"/example-path"}]],"is_active":true,"order":1,"description":""}
```

---

## updateRule

Sends the rule fields you pass in a `PATCH` request. Fields you leave out keep their values: a call that does not send `criteria` leaves the `criteria` of the rule unchanged.

```typescript
function updateRule(params: {
  applicationId: number;
  phase: "request" | "response";
  ruleId: number;
  data: ApiUpdateRulePayload;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<AzionRule>>;
```

| Parameter       | Type                                            | Required | Description                                    |
| --------------- | ----------------------------------------------- | -------- | ---------------------------------------------- |
| `applicationId` | `number`                                        | Yes      | The ID of the application.                     |
| `phase`         | `'request' \| 'response'`                       | Yes      | The phase of the rule.                         |
| `ruleId`        | `number`                                        | Yes      | The ID of the rule to update.                  |
| `data`          | [`ApiUpdateRulePayload`](#apicreaterulepayload) | Yes      | The fields to change. Every field is optional. |
| `options`       | [`AzionClientOptions`](#azionclientoptions)     | No       | Request options.                               |

Returns `data` as the updated [AzionRule](#azionrule).

```typescript
import { updateRule } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const ruleId = 123457; // Replace with the actual rule ID

const { data: updatedRule, error } = await updateRule({
  applicationId,
  phase: 'request',
  ruleId,
  data: { name: 'Example Rule Updated', behaviors: [{ name: 'redirect_to_302', target: 'https://example.com/new' }] },
});

if (error) {
  console.error('Error updating rule:', error);
} else {
  console.log('Updated rule:', JSON.stringify(updatedRule));
}
```

Output:

```text
Updated rule: {"id":123457,"name":"Example Rule Updated","phase":"request","behaviors":[{"name":"redirect_to_302","target":"https://example.com/new"}],"criteria":[[{"variable":"${uri}","operator":"starts_with","conditional":"if","input_value":"/example-path"}]],"is_active":true,"order":1,"description":""}
```

---

## deleteRule

Deletes a rule of an application by its phase and ID.

```typescript
function deleteRule(params: {
  applicationId: number;
  phase: "request" | "response";
  ruleId: number;
  options?: AzionClientOptions;
}): Promise<AzionApplicationResponse<void>>;
```

| Parameter       | Type                                        | Required | Description                   |
| --------------- | ------------------------------------------- | -------- | ----------------------------- |
| `applicationId` | `number`                                    | Yes      | The ID of the application.    |
| `phase`         | `'request' \| 'response'`                   | Yes      | The phase of the rule.        |
| `ruleId`        | `number`                                    | Yes      | The ID of the rule to delete. |
| `options`       | [`AzionClientOptions`](#azionclientoptions) | No       | Request options.              |

A successful delete returns `error` with the message `Expected JSON response, but got: `, so the sample reads the rule back with [getRule](#getrule). A `404` error confirms the delete.

```typescript
import { deleteRule, getRule } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID
const ruleId = 123457; // Replace with the actual rule ID

const { error: deleteError } = await deleteRule({ applicationId, phase: 'request', ruleId });

// On success (HTTP 204) the envelope still carries an error, so confirm by reading it back
const { error } = await getRule({ applicationId, phase: 'request', ruleId });
if (error) {
  console.log(`Rule ${ruleId} deleted (read back: ${error.message})`);
} else {
  console.error('Error deleting rule:', deleteError);
}
```

Output:

```text
Rule 123457 deleted (read back: HTTP error! Status: 404 - NOT FOUND)
```

---

## Application methods

An application that [createApplication](#createapplication) or [getApplication](#getapplication) returns carries the sub-resource functions as methods, already bound to its ID. Each method takes the same object as the matching function, without `applicationId`. The rule methods sit under `rules.request` and `rules.response`, which also fix the `phase`.

| Property                          | Type                    | Methods                                                                                                                     |
| --------------------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `origins`                         | `OriginOperations`      | `createOrigin`, `getOrigins`, `getOrigin`, `updateOrigin`, `deleteOrigin`                                                   |
| `cache`                           | `CacheOperations`       | `createCacheSetting`, `getCacheSettings`, `getCacheSetting`, `updateCacheSetting`, `deleteCacheSetting`                     |
| `devices`                         | `DeviceGroupOperations` | `createDeviceGroup`, `getDeviceGroups`, `getDeviceGroup`, `updateDeviceGroup`, `deleteDeviceGroup`                          |
| `functions`                       | `FunctionOperations`    | `createFunctionInstance`, `getFunctionInstances`, `getFunctionInstance`, `updateFunctionInstance`, `deleteFunctionInstance` |
| `rules.request`, `rules.response` | `RuleOperations`        | `createRule`, `getRules`, `getRule`, `updateRule`, `deleteRule`                                                             |

A list method needs an object argument, even an empty one: `{}`. This sample reads an application and lists each of its sub-resources through the methods:

```typescript
import { getApplication } from 'azion/applications';

const applicationId = 1234567890; // Replace with the actual application ID

// The application object carries the sub-resource operations, already bound to its ID
const { data: app, error } = await getApplication({ applicationId });
if (!app) throw new Error(error?.message);

const { data: cache } = await app.cache.getCacheSettings({});
console.log('app.cache.getCacheSettings:', cache?.results.map((c) => c.name));
const { data: origins } = await app.origins.getOrigins({});
console.log('app.origins.getOrigins:', origins?.results.map((o) => o.name));
const { data: rules } = await app.rules.request.getRules({});
console.log('app.rules.request.getRules:', rules?.results.map((r) => r.name));
const { data: devices } = await app.devices.getDeviceGroups({});
console.log('app.devices.getDeviceGroups:', devices?.count);
const { data: functions } = await app.functions.getFunctionInstances({});
console.log('app.functions.getFunctionInstances:', functions?.count);
```

Output:

```text
app.cache.getCacheSettings: [ 'my-other-cache-setting' ]
app.origins.getOrigins: [ 'my-origin-updated' ]
app.rules.request.getRules: [ 'Default Rule' ]
app.devices.getDeviceGroups: 0
app.functions.getFunctionInstances: 0
```

---

## Errors

The application-level functions throw these messages inside an `Error`. The other functions return them in `error.message`, and `error.operation` names the call, such as `create device group`.

| Message                                  | Cause                                                                                                                                                                                                                                                                                          | What to do                                                                                                                                                                        |
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `HTTP error! Status: 401 - UNAUTHORIZED` | No valid token reached the call: `AZION_TOKEN` is unset or holds an invalid token, and no client `token` was passed.                                                                                                                                                                           | Set `AZION_TOKEN` to a valid [personal token](/en/documentation/fundamentals/personal-tokens/), or pass `token` to [createAzionApplicationClient](#createazionapplicationclient). |
| `HTTP error! Status: 404 - NOT FOUND`    | No application has that ID, or the application holds no object with that ID or origin key.                                                                                                                                                                                                     | Check the ID with the matching list function, such as [getApplications](#getapplications) or [getOrigins](#getorigins).                                                           |
| `HTTP error! Status: 400 - BAD REQUEST`  | API v3 refused the payload. The message does not carry the reason the API gives. Causes include `application_acceleration` in a create request, a cache setting on an application with no origin, a device group name with a space or a hyphen, and `sort` or `order` in a cache setting list. | Compare the payload with the section of the function you called, and remove or change the field it names.                                                                         |
| `Expected JSON response, but got: `      | A delete succeeded, and the API answered with an empty body.                                                                                                                                                                                                                                   | Read the object back. A `404` error confirms the delete.                                                                                                                          |

---

## Types

The `azion/applications` module exports these types, except where a type says otherwise. Import them with `import type`.

### AzionApplicationsClient

The client that [createAzionApplicationClient](#createazionapplicationclient) returns. Each method takes one object.

| Method              | Argument                                                                                              | Returns                                                         |
| ------------------- | ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| `createApplication` | `{ data: ApiCreateApplicationPayload; options?: AzionClientOptions }`                                 | `Promise<AzionApplicationResponse<AzionApplication>>`           |
| `getApplication`    | `{ applicationId: number; options?: AzionClientOptions }`                                             | `Promise<AzionApplicationResponse<AzionApplication>>`           |
| `getApplications`   | `{ params?: AzionApplicationCollectionOptions; options?: AzionClientOptions }`                        | `Promise<AzionApplicationCollectionResponse<AzionApplication>>` |
| `putApplication`    | `{ applicationId: number; data: ApiUpdateApplicationPayload; options?: AzionClientOptions }`          | `Promise<AzionApplicationResponse<AzionApplication>>`           |
| `patchApplication`  | `{ applicationId: number; data: Partial<ApiUpdateApplicationPayload>; options?: AzionClientOptions }` | `Promise<AzionApplicationResponse<AzionApplication>>`           |
| `deleteApplication` | `{ applicationId: number; options?: AzionClientOptions }`                                             | `Promise<AzionApplicationResponse<void>>`                       |

### CreateAzionApplicationClient

The type of [createAzionApplicationClient](#createazionapplicationclient).

```typescript
type CreateAzionApplicationClient = (config?: Partial<{
  token: string;
  options?: AzionClientOptions;
}>) => AzionApplicationsClient;
```

### AzionClientOptions

Request options that every function takes in `options`.

| Property | Type      | Required | Description                                           |
| -------- | --------- | -------- | ----------------------------------------------------- |
| `debug`  | `boolean` | No       | Turns on debug mode.                                  |
| `force`  | `boolean` | No       | Declared by the type. No sample on this page uses it. |

### AzionApplicationResponse

The envelope that every function except the list functions returns. For how to read it, refer to [Response envelope](#response-envelope).

| Property | Type                                     | Required | Description                                                                         |
| -------- | ---------------------------------------- | -------- | ----------------------------------------------------------------------------------- |
| `data`   | `T`                                      | No       | The result of the call.                                                             |
| `error`  | `{ message: string; operation: string }` | No       | The error message and the operation that failed. A successful delete also fills it. |

### AzionApplicationCollectionResponse

The envelope that the list functions return.

| Property              | Type                                                     | Required | Description                                               |
| --------------------- | -------------------------------------------------------- | -------- | --------------------------------------------------------- |
| `data`                | `{ count; total_pages; schema_version; links; results }` | No       | The page of results.                                      |
| `data.count`          | `number`                                                 | Yes      | The number of objects in the whole list, not on the page. |
| `data.total_pages`    | `number`                                                 | Yes      | The number of pages.                                      |
| `data.schema_version` | `number`                                                 | Yes      | The schema version of the API response.                   |
| `data.links`          | `{ previous: string \| null; next: string \| null }`     | Yes      | The previous and next pages.                              |
| `data.results`        | `T[]`                                                    | Yes      | The objects on the page.                                  |
| `error`               | `{ message: string; operation: string }`                 | No       | The error message and the operation that failed.          |

### AzionApplication

An application: the fields of [ApiBaseApplicationPayload](#apibaseapplicationpayload), plus the ID and the [application methods](#application-methods). `AzionApplicationSettings` is the same shape without the methods.

| Property    | Type                                                    | Required | Description                          |
| ----------- | ------------------------------------------------------- | -------- | ------------------------------------ |
| `id`        | `number`                                                | Yes      | The ID of the application.           |
| `origins`   | `OriginOperations`                                      | Yes      | The origin methods.                  |
| `cache`     | `CacheOperations`                                       | Yes      | The cache setting methods.           |
| `devices`   | `DeviceGroupOperations`                                 | Yes      | The device group methods.            |
| `functions` | `FunctionOperations`                                    | Yes      | The function instance methods.       |
| `rules`     | `{ request: RuleOperations; response: RuleOperations }` | Yes      | The rule methods, one set per phase. |

### ApiBaseApplicationPayload

The settings of an application. `name` is required and every other field is optional. `ApiCreateApplicationPayload`, which the module does not export, has the same shape, and `ApiUpdateApplicationPayload` makes every field optional. API v3 refuses `application_acceleration` in a create request.

```typescript
interface ApiBaseApplicationPayload {
  name: string;
  delivery_protocol?: DeliveryProtocol;
  http3?: boolean;
  http_port?: HttpPort[];
  https_port?: HttpsPort[];
  minimum_tls_version?: TlsVersion;
  active?: boolean;
  debug_rules?: boolean;
  application_acceleration?: boolean;
  caching?: boolean;
  device_detection?: boolean;
  edge_firewall?: boolean;
  edge_functions?: boolean;
  image_optimization?: boolean;
  l2_caching?: boolean;
  load_balancer?: boolean;
  raw_logs?: boolean;
  web_application_firewall?: boolean;
  supported_ciphers?: SupportedCiphers;
}
```

The enums of the application settings, which the module exports:

```typescript
enum DeliveryProtocol {
  HTTP = "http",
  HTTPS = "https",
  HTTP_HTTPS = "http,https"
}
enum HttpPort {
  PORT_80 = 80,
  PORT_8008 = 8008,
  PORT_8080 = 8080
}
enum HttpsPort {
  PORT_443 = 443,
  PORT_8443 = 8443,
  PORT_9440 = 9440,
  PORT_9441 = 9441,
  PORT_9442 = 9442,
  PORT_9443 = 9443
}
enum TlsVersion {
  TLS_1_0 = "tls_1_0",
  TLS_1_1 = "tls_1_1",
  TLS_1_2 = "tls_1_2",
  TLS_1_3 = "tls_1_3"
}
enum SupportedCiphers {
  ALL = "all",
  TLSv1_2_2018 = "TLSv1.2_2018",
  TLSv1_2_2019 = "TLSv1.2_2019",
  TLSv1_2_2021 = "TLSv1.2_2021",
  TLSv1_3_2022 = "TLSv1.3_2022"
}
```

### ApiListApplicationsParams

Pagination and ordering for [getApplications](#getapplications). `AzionApplicationCollectionOptions`, which the client method takes, has the same keys.

| Property    | Type             | Required | Description                                           |
| ----------- | ---------------- | -------- | ----------------------------------------------------- |
| `page`      | `number`         | No       | The page number.                                      |
| `page_size` | `number`         | No       | The number of applications per page.                  |
| `sort`      | `'name' \| 'id'` | No       | Declared by the type. No sample on this page uses it. |
| `order_by`  | `string`         | No       | Declared by the type. No sample on this page uses it. |

### AzionOrigin

An origin, with its `origin_key`. `ApiCreateOriginPayload` takes every field below except `id` and `method`, all required, plus optional `origin_path`, `hmac_authentication`, `hmac_region_name`, `hmac_access_key`, `hmac_secret_key`, `connection_timeout`, and `timeout_between_bytes`. `ApiUpdateOriginRequest` makes every field optional and requires `id`.

```typescript
interface AzionOrigin {
  id: number;
  origin_key: string;
  name: string;
  origin_type: OriginType;
  addresses: Address[];
  origin_protocol_policy: OriginProtocolPolicy;
  is_origin_redirection_enabled: boolean;
  host_header: string;
  method: string;
  origin_path: string;
  connection_timeout: number;
  timeout_between_bytes: number;
  hmac_authentication: boolean;
  hmac_region_name: string;
  hmac_access_key: string;
  hmac_secret_key: string;
}
interface Address {
  address: string;
  weight?: number | null;
  server_role?: ServerRole;
  is_active?: boolean;
}
```

The enums of an origin, which the module does not export:

```typescript
enum OriginType {
  SINGLE_ORIGIN = "single_origin",
  LOAD_BALANCER = "load_balancer"
}
enum OriginProtocolPolicy {
  PRESERVE = "preserve",
  HTTP = "http",
  HTTPS = "https"
}
enum ServerRole {
  PRIMARY = "primary",
  BACKUP = "backup"
}
```

### AzionCacheSetting

A cache setting: the fields of [ApiBaseCacheSettingPayload](#apibasecachesettingpayload), plus its `id` (`number`).

### ApiBaseCacheSettingPayload

The settings of a cache setting. `name` is required and every other field is optional. `ApiUpdateCacheSettingPayload` makes every field optional.

```typescript
interface ApiBaseCacheSettingPayload {
  name: string;
  browser_cache_settings?: BrowserCacheSettings;
  browser_cache_settings_maximum_ttl?: number;
  cdn_cache_settings?: CdnCacheSettings;
  cdn_cache_settings_maximum_ttl?: number;
  cache_by_query_string?: CacheByQueryString;
  query_string_fields?: string[];
  enable_query_string_sort?: boolean;
  cache_by_cookies?: CacheByCookies;
  cookie_names?: string[];
  adaptive_delivery_action?: AdaptiveDeliveryAction;
  device_group?: string[];
  enable_caching_for_post?: boolean;
  l2_caching_enabled?: boolean;
  is_slice_configuration_enabled?: boolean;
  is_slice_edge_caching_enabled?: boolean;
  is_slice_l2_caching_enabled?: boolean;
  slice_configuration_range?: number;
  enable_caching_for_options?: boolean;
  enable_stale_cache?: boolean;
  l2_region?: string | null;
}
```

The enums of a cache setting, which the module does not export:

```typescript
enum BrowserCacheSettings {
  HONOR = "honor",
  OVERRIDE = "override",
  IGNORE = "ignore"
}
enum CdnCacheSettings {
  HONOR = "honor",
  OVERRIDE = "override"
}
enum CacheByQueryString {
  IGNORE = "ignore",
  WHITELIST = "whitelist",
  BLACKLIST = "blacklist",
  ALL = "all"
}
enum CacheByCookies {
  IGNORE = "ignore",
  WHITELIST = "whitelist",
  BLACKLIST = "blacklist",
  ALL = "all"
}
enum AdaptiveDeliveryAction {
  IGNORE = "ignore",
  OPTIMIZE = "optimize"
}
```

### AzionDeviceGroup

A device group. `ApiCreateDeviceGroupPayload` and `ApiUpdateDeviceGroupPayload`, which the module does not export, take `name` and `user_agent`, both required on create and optional on update.

| Property     | Type     | Required | Description                                                           |
| ------------ | -------- | -------- | --------------------------------------------------------------------- |
| `id`         | `number` | Yes      | The ID of the device group.                                           |
| `name`       | `string` | Yes      | The name of the group, with no spaces and no hyphens.                 |
| `user_agent` | `string` | Yes      | The regular expression compared with the `User-Agent` request header. |

### AzionFunctionInstance

A function instance. The API returns the four fields below, as the samples show.

| Property           | Type                      | Description                               |
| ------------------ | ------------------------- | ----------------------------------------- |
| `id`               | `number`                  | The ID of the function instance.          |
| `edge_function_id` | `number`                  | The ID of the function the instance runs. |
| `name`             | `string`                  | The name of the function instance.        |
| `args`             | `Record<string, unknown>` | The arguments the function receives.      |

The type declares other fields: `id` plus the fields of `ApiBaseFunctionInstancePayload`, which are `name`, `code`, `language` (`'JavaScript'`), `initiator_type` (`'edge_application' \| 'edge_firewall'`), `active`, and `json_args`. `ApiUpdateFunctionInstancePayload` makes those fields optional.

### ApiCreateFunctionInstancePayload

The payload of [createFunctionInstance](#createfunctioninstance). The module does not export this type.

| Property           | Type                      | Required | Description                                           |
| ------------------ | ------------------------- | -------- | ----------------------------------------------------- |
| `name`             | `string`                  | Yes      | The name of the function instance.                    |
| `edge_function_id` | `number`                  | Yes      | The ID of the function the instance runs.             |
| `args`             | `Record<string, unknown>` | Yes      | The arguments the function receives.                  |
| `active`           | `boolean`                 | No       | Declared by the type. No sample on this page uses it. |

### AzionRule

A rule: the fields of [ApiCreateRulePayload](#apicreaterulepayload), plus `id` (`number`). `AzionRule` declares `is_active` and `order` as required, and every rule in the samples carries both.

### ApiCreateRulePayload

The payload of [createRule](#createrule). `ApiUpdateRulePayload` makes every field optional.

| Property      | Type                      | Required | Description                                                                                                                                                         |
| ------------- | ------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`        | `string`                  | Yes      | The name of the rule.                                                                                                                                               |
| `phase`       | `'request' \| 'response'` | Yes      | The phase of the rule.                                                                                                                                              |
| `criteria`    | `Criterion[][]`           | Yes      | The condition groups. Each `Criterion` holds `variable` (`string`), `operator` (`string`), `conditional` (`'if' \| 'and' \| 'or'`), and `input_value` (`string`).   |
| `behaviors`   | `Behavior[]`              | Yes      | The actions. Each `Behavior` holds `name` (`string`) and an optional `target`: a `string`, `null`, or `{ captured_array: string; subject: string; regex: string }`. |
| `is_active`   | `boolean`                 | No       | Whether the rule is active. A rule created without it is active.                                                                                                    |
| `order`       | `number`                  | No       | The position of the rule in its phase.                                                                                                                              |
| `description` | `string`                  | No       | The description of the rule.                                                                                                                                        |

### List parameters

The `params` object of each sub-resource list function declares these keys. The samples send only `page` and `page_size`. `ApiListDeviceGroupsParams` is not exported.

| Type                             | Declared keys                                                                                     |
| -------------------------------- | ------------------------------------------------------------------------------------------------- |
| `ApiListOriginsParams`           | `page`, `page_size`, `sort` (`'name' \| 'id'`), `order` (`'asc' \| 'desc'`), `filter`             |
| `ApiListCacheSettingsParams`     | `page`, `page_size`, `sort` (`'name' \| 'id'`), `order` (`'asc' \| 'desc'`)                       |
| `ApiListDeviceGroupsParams`      | `page`, `page_size`, `sort` (`'name' \| 'id'`), `order` (`'asc' \| 'desc'`)                       |
| `ApiListFunctionInstancesParams` | `page`, `page_size`, `sort` (`'name' \| 'id'`), `order` (`'asc' \| 'desc'`), `order_by`, `filter` |
| `ApiListRulesParams`             | `page`, `page_size`, `sort` (`string`), `order` (`'asc' \| 'desc'`), `filter`                     |

---

## Related resources

- [Azion Lib](/en/documentation/devtools/azion-lib.md): The Azion Lib modules and the npm package each one ships in.
- [Client](/en/documentation/devtools/azion-lib/client.md): The client that exposes Applications next to Storage, SQL, Purge, Domains, and AI.
- [Domains](/en/documentation/devtools/azion-lib/domains.md): The Azion Lib functions that point a domain to an application by its ID.
- [Applications | v3](/en/documentation/platform/applications/v3.md): The API v3 application, with its delivery protocols, ports, and settings.
