# Azion Application module

import DocButton from '~/components/webkit/DocButton.vue';

The Azion **Application** module provides a comprehensive interface to interact with the Azion **Applications** API. This module allows you to manage applications and their components including cache settings, device groups, function instances, origins, and Rules Engine configurations.

<DocButton href="/en/documentation/products/azion-lib/overview/" label="Go to Azion Libraries Overview" kind="secondary" target="_blank" size="medium" />

You can interact with the API using a `client` or calling the methods directly from the library. When making direct calls, you can use the environment variables to configure the `client` without passing the token and debug parameters directly.

This is an example of how a `.env` file with your environment variables may look like:

```sh
AZION_TOKEN=your-api-token
AZION_DEBUG=true
```

| Variable | Description |
|----------|-------------|
| `AZION_TOKEN` | Your Azion API token. |
| `AZION_DEBUG` | Enable debug mode (true/false). |

:::tip
Setting `AZION_DEBUG` to `true` enables **Debug mode**. This mode provides detailed logging of the API requests and responses.
:::

## Usage
---
### `createClient`

**TypeScript example**:

```typescript
import createClient from 'azion/applications';

const client = createClient({
  token: 'your-api-token',
  options: { debug: true }
});
```

### Usage with Applications

#### `createApplication`

Creates a new application.

**TypeScript example**:

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

// Create a new application
const { data: newApp, error } = await createApplication({
  data: { 
    name: "My Applications",
    delivery_protocol: "http,https",
    application_acceleration: true
  }
});
```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `data` | `{ name: string; delivery_protocol: string; application_acceleration: boolean; }` | The data for the new application. |
| `options?` | `{ debug?: boolean }` | Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionApplication>>` | The created application object or error if creation failed. |

#### `getApplications`

Lists all applications.

**TypeScript example**:
```typescript
import { getApplications } from 'azion/applications';

// List all applications
const { data: apps, error } = await getApplications({
  params: { page: 1, page_size: 20 }
});
```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `params?` | `{ page?: number; page_size?: number; order?: 'id'} \| 'name'; sort?: 'asc' \| 'desc'; }`| Optional parameters for filtering and pagination. |
| `options?` | `{ debug?: boolean }` | Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationCollectionResponse<AzionApplication>>` | A collection of applications or error if retrieval failed. |

#### `getApplication`

Retrieves a specific application.

**TypeScript example**:

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

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

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

if (error) {
  console.error("Error retrieving application:", error);
} else {
  console.log("Application details:", app);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `applicationId`  | Number | The ID of the application to retrieve. |
| `options?` | `{ debug?: boolean }` | Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionApplication>>` | The retrieved application object or error if not found. |


#### `updateApplication`

Updates an existing application.

**TypeScript example**:

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

// Update an existing application
const applicationId = 12345; // Replace with the actual application ID

const updateData = {
  name: "Updated Applications",
  delivery_protocol: "https",
  application_acceleration: false
};

const { data: updatedApp, error } = await updateApplication(applicationId, updateData, { debug: true });

if (error) {
  console.error("Error updating application:", error);
} else {
  console.log("Updated application details:", updatedApp);
}

```
**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `applicationId` | Number | The ID of the application to update. |
| `data` | `{ name?: string; delivery_protocol?: string; application_acceleration?: boolean; }`| The updated data for the application. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionApplication>>` | The updated application object or error if the update failed. |

#### `deleteApplication`

Deletes an application.

**TypeScript example**:

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

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

const { data: deletedApp, error } = await deleteApplication(applicationId, { debug: true });

if (error) {
  console.error("Error deleting application:", error);
} else {
  console.log("Application deleted successfully:", deletedApp);
}


```
**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `applicationId` | Number | The ID of the application to delete. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionDeletedApplication>>` | Confirmation of deletion or error if the operation failed. |

---

### Cache Settings

#### `createCacheSetting`

Creates a new cache setting.

**TypeScript example**:

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

// Create a new cache setting
const cacheSettingData = {
  name: "My Cache Setting",
  browser_cache_settings: "private",
  cdn_cache_settings: "public"
};

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

if (error) {
  console.error("Error creating cache setting:", error);
} else {
  console.log("Cache setting created successfully:", newCacheSetting);
}


```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `data`  | `{ name: string; browser_cache_settings: string; cdn_cache_settings: string; }` | The data for the new cache setting. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionCacheSetting>>` | The created cache setting object or error if creation failed. |

---

#### `getCacheSetting`

Retrieve a specific cache setting.

**TypeScript example**:

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

// Retrieve a specific cache setting
const cacheSettingId = 12345; // Replace with the actual cache setting ID

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

if (error) {
  console.error("Error retrieving cache setting:", error);
} else {
  console.log("Cache setting details:", cacheSetting);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `cacheSettingId`  | Number | The ID of the cache setting to retrieve. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionCacheSetting>>` | The retrieved cache setting object or error if not found. |


#### `getCacheSettings`

Lists all cache settings.

**TypeScript example**:

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

// List all cache settings with optional pagination and sorting
const { data: cacheSettings, error } = await getCacheSettings({
  params: { page: 1, page_size: 20, order: 'name', sort: 'asc' },
  debug: true
});

if (error) {
  console.error("Error retrieving cache settings:", error);
} else {
  console.log("Cache settings list:", cacheSettings);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `params?` | `{ page?: number; page_size?: number; order?: 'id' \| 'name'; sort?: 'asc' \| 'desc'; }` |  Optional parameters for filtering and pagination. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationCollectionResponse<AzionCacheSetting>>` | A collection of cache settings or error if retrieval failed. |

---

#### `updateCacheSetting`

Updates an existing cache setting.

**TypeScript example**:

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

// Update an existing cache setting
const cacheSettingId = 12345; // Replace with the actual cache setting ID

const updateData = {
  name: "Updated Cache Setting",
  browser_cache_settings: "no-cache",
  cdn_cache_settings: "private"
};

const { data: updatedCacheSetting, error } = await updateCacheSetting(cacheSettingId, updateData, { debug: true });

if (error) {
  console.error("Error updating cache setting:", error);
} else {
  console.log("Updated cache setting details:", updatedCacheSetting);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `cacheSettingId` | Number | The ID of the cache setting to update. |
| `data` | `{ name?: string; browser_cache_settings?: string; cdn_cache_settings?: string; }`| The updated data for the cache setting.|
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionCacheSetting>>` | The updated cache setting object or error if the update failed. |


#### `deleteCacheSetting`

Deletes a cache setting.

**TypeScript example**:

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

// Delete an existing cache setting
const cacheSettingId = 12345; // Replace with the actual cache setting ID

const { data: deletedCacheSetting, error } = await deleteCacheSetting(cacheSettingId, { debug: true });

if (error) {
  console.error("Error deleting cache setting:", error);
} else {
  console.log("Cache setting deleted successfully:", deletedCacheSetting);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `cacheSettingId` | Number | The ID of the cache setting to delete. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionDeletedCacheSetting>>` | Confirmation of deletion or error if the operation failed. |

---

### Device Groups

#### `createDeviceGroup`

Creates a new device group.

**TypeScript example**:

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

// Create a new device group
const deviceGroupData = {
  name: "Mobile Devices",
  user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
};

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

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

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `data` | `{ name: string; user_agent: string; }` | The data for the new device group. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionDeviceGroup>>` | The created device group object or error if creation failed. |

#### `getDeviceGroup`

Retrieves a specific device group.

**TypeScript example**:

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

// Retrieve a specific device group
const deviceGroupId = 12345; // Replace with the actual device group ID

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

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

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `deviceGroupId` | Number | The ID of the device group to retrieve. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionDeviceGroup>>` |  The retrieved device group object or error if not found. |


#### `getDeviceGroups`

Lists all device groups.

**TypeScript example**:

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

// List all device groups with optional pagination and sorting
const { data: deviceGroups, error } = await getDeviceGroups({
  params: { page: 1, page_size: 20, order: 'name', sort: 'asc' },
  debug: true
});

if (error) {
  console.error("Error retrieving device groups:", error);
} else {
  console.log("Device groups list:", deviceGroups);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `params?` | `{ page?: number; page_size?: number; order?: 'id' \| 'name'; sort?: 'asc' \| 'desc'; }` | Optional parameters for filtering and pagination. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationCollectionResponse<AzionDeviceGroup>>` | The retrieved device group object or error if not found. |


#### `updateDeviceGroup`

Updates an existing device group.

**TypeScript example**:

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

// Update an existing device group
const deviceGroupId = 12345; // Replace with the actual device group ID
const updatedName = "Updated Device Group Name";  // Using a variable for the name

const updateData = {
  name: updatedName
};

const { data: updatedDeviceGroup, error } = await updateDeviceGroup(deviceGroupId, updateData, { debug: true });

if (error) {
  console.error("Error updating device group:", error);
} else {
  console.log("Updated device group details:", updatedDeviceGroup);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `deviceGroupId` | Number | The ID of the device group to update. |
| `data` | `{ name?: string; user_agent?: string; }` | The updated data for the device group. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionDeviceGroup>>` | The updated device group object or error if the update failed. |


#### `deleteDeviceGroup`

Deletes a device group.

**TypeScript example**:

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

// Delete a specific device group
const deviceGroupId = 12345; // Replace with the actual device group ID

const { data: deletedDeviceGroup, error } = await deleteDeviceGroup(deviceGroupId, { debug: true });

if (error) {
  console.error("Error deleting device group:", error);
} else {
  console.log("Device group deleted successfully:", deletedDeviceGroup);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `deviceGroupId` | Number | The ID of the device group to delete. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionDeletedDeviceGroup>>`| Confirmation of deletion or error if the operation failed. |

---

### Function Instances

#### `createFunctionInstance`

Creates a new function instance.

**TypeScript example**:

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

// Define the data for the new function instance
const functionInstanceData = {
  name: "MyFunctionInstance",
  entry_point: "index.handler", // Replace with the entry point of your function
  timeout: 30 // Adjust the timeout as needed
};

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

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

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `data` | `ApiCreateFunctionInstancePayload` | The data for the new function instance. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionFunctionInstance>>`| The created function instance object or error if creation failed. |


#### `getFunctionInstance`

Retrieves a specific function instance.

**TypeScript example**:

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

// Retrieve a specific function instance
const functionInstanceId = 12345; // Replace with the actual function instance ID

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

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

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `functionInstanceId` | Number | The ID of the function instance to retrieve. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode.

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionFunctionInstance>>`| The retrieved function instance object or error if not found. |


#### `getFunctionInstances`

Lists all function instances.

**TypeScript example**:

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

// List all function instances with optional parameters for pagination
const params = {
  page: 1, // Page number for pagination
  page_size: 20, // Number of items per page
  order: 'name', // Order by name
  sort: 'asc' // Sort in ascending order
};

const { data: functionInstances, error } = await getFunctionInstances(params, { debug: true });

if (error) {
  console.error("Error retrieving function instances:", error);
} else {
  console.log("List of function instances:", functionInstances);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `params?` | `ApiListFunctionInstancesParams` | Optional parameters for filtering and pagination. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationCollectionResponse<AzionFunctionInstance>>`| A collection of function instances or error if retrieval failed.


#### `updateFunctionInstance`

Updates an existing function instance.

**TypeScript example**:

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

// Define the ID of the function instance and the updated data
const functionInstanceId = 12345; // Replace with the actual function instance ID
const updatedData = {
  name: "Updated Function Instance Name", // New name for the function instance
  entry_point: "newIndex.handler", // Updated entry point (example)

};

// Update the function instance
const { data: updatedFunctionInstance, error } = await updateFunctionInstance(functionInstanceId, updatedData, { debug: true });

if (error) {
  console.error("Error updating function instance:", error);
} else {
  console.log("Updated function instance details:", updatedFunctionInstance);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `functionInstanceId` | Number | The ID of the function instance to update. |
| `data` | `ApiUpdateFunctionInstancePayload` | The updated data for the function instance. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionFunctionInstance>>`| The updated function instance object or error if the update failed. |


#### `deleteFunctionInstance`

Deletes a function instance.

**TypeScript example**:

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

// Define the ID of the function instance to delete
const functionInstanceId = 12345; // Replace with the actual function instance ID

// Delete the function instance
const { data: deletedFunctionInstance, error } = await deleteFunctionInstance(functionInstanceId, { debug: true });

if (error) {
  console.error("Error deleting function instance:", error);
} else {
  console.log("Function instance deleted successfully:", deletedFunctionInstance);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `functionInstanceId` | Number |  The ID of the function instance to delete. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionDeletedFunctionInstance>>`| Confirmation of deletion or error if the operation failed.|

---

### Origins

#### `createOrigin`

Creates a new origin.

**TypeScript example**:

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

// Define the data for the new origin
const newOriginData = {
  name: "My New Origin", // Name of the origin
  url: "https://example.com" // URL of the origin
};

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

if (error) {
  console.error("Error creating origin:", error);
} else {
  console.log("Created origin:", newOrigin);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `data` | `{ name: string; url: string; }` | The data for the new origin. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode.

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionOrigin>>`| The created origin object or error if creation failed. |


#### `getOrigin`

Retrieves a specific origin.

**TypeScript example**:

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

// Define the ID of the origin to retrieve
const originId = 12345; // Replace with the actual origin ID

// Retrieve the specific origin
const { data: origin, error } = await getOrigin(originId, { debug: true });

if (error) {
  console.error("Error retrieving origin:", error);
} else {
  console.log("Retrieved origin:", origin);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `originId` | Number | The ID of the origin to retrieve. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionOrigin>>`| The retrieved origin object or error if not found. |

#### `getOrigins`

Lists all origins.

**TypeScript example**:

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

// Define the optional parameters for filtering and pagination
const params = {
  page: 1, // Page number
  page_size: 20, // Number of items per page
  order: 'name', // Sort order by name or id
  sort: 'asc' // Sorting direction (ascending)
};

// Retrieve all origins with optional pagination and sorting
const { data: origins, error } = await getOrigins(params, { debug: true });

if (error) {
  console.error("Error retrieving origins:", error);
} else {
  console.log("List of origins:", origins);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `params?` | `{ page?: number; page_size?: number; order?: 'id' \| 'name'; sort?: 'asc' \| 'desc'; }` | Optional parameters for filtering and pagination. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationCollectionResponse<AzionOrigin>>`| A collection of origins or error if retrieval failed. |


#### `updateOrigin`

Updates an existing origin.

**TypeScript example**:

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

// Define the origin ID and updated data
const originId = 12345; // Replace with the actual origin ID
const updatedData = {
  name: "Updated Origin Name", // New name for the origin
  url: "https://new-url.com"   // New URL for the origin
};

// Update the origin with the specified ID
const { data: updatedOrigin, error } = await updateOrigin(originId, updatedData, { debug: true });

if (error) {
  console.error("Error updating origin:", error);
} else {
  console.log("Updated origin:", updatedOrigin);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `originId` | Number | The ID of the origin to update. |
| `data` | `{ name?: string; url?: string; }` | The updated data for the origin. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionOrigin>>`| The updated origin object or error if the update failed. |

#### `deleteOrigin`

Deletes an origin.

**TypeScript example**:

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

// Define the origin ID to delete
const originId = 12345; // Replace with the actual origin ID

// Delete the origin with the specified ID
const { data: deletedOrigin, error } = await deleteOrigin(originId, { debug: true });

if (error) {
  console.error("Error deleting origin:", error);
} else {
  console.log("Deleted origin:", deletedOrigin);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `originId` | Number | The ID of the origin to delete. |
| `options?` | `{ debug?: boolean }`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionDeletedOrigin>>`| Confirmation of deletion or error if the operation failed. |

---

### Rules Engine

#### `createRule`

Creates a new rule.

**TypeScript example**:

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

// Define the data for the new rule
const ruleData = {
  name: "Example Rule", 
  conditions: {
    path: "/example-path"
  },
  actions: {
    redirect: {
      url: "https://example.com"
    }
  }
};

// Create a new rule
const { data: newRule, error } = await createRule(ruleData, { debug: true });

if (error) {
  console.error("Error creating rule:", error);
} else {
  console.log("Created rule:", newRule);
}

```
**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `data` | `{ApiCreateRulePayload` | The data for the new rule. |
| `options?` | `AzionClientOptions`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionRule>>`| The created rule object or error if creation failed. |


#### `getRule`

Retrieves a specific rule.

**TypeScript example**:

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

// Define the rule ID to retrieve
const ruleId = 123;

// Retrieve the specific rule
const { data: rule, error } = await getRule(ruleId, { debug: true });

if (error) {
  console.error("Error retrieving rule:", error);
} else {
  console.log("Retrieved rule:", rule);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `ruleId` | Number | The ID of the rule to retrieve.
| `options?` | `AzionClientOptions`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionRule>>`| The retrieved rule object or error if not found. |


#### `getRules`

Lists all rules.

**TypeScript example**:

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

// Optional parameters for filtering and pagination
const params = {
  page: 1,
  page_size: 10,
  order: 'id',
  sort: 'asc',
};

// Fetch the collection of rules with optional parameters
const { data: rules, error } = await getRules(params, { debug: true });

if (error) {
  console.error("Error retrieving rules:", error);
} else {
  console.log("Retrieved rules:", rules);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `params?` | `ApiListRulesParams` | Optional parameters for filtering and pagination. |
| `options?` | `AzionClientOptions`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationCollectionResponse<AzionRule>>`| A collection of rules or error if retrieval failed. |


#### `updateRule`

Updates an existing rule.

**TypeScript example**:

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

// The ID of the rule to update
const ruleId = 123;

// The updated data for the rule
const data = {
  name: "Updated Rule Name",
  condition: "new_condition_expression",
  action: "new_action_to_perform",
};

// Optional parameters including debug mode
const options = { debug: true };

// Update the rule with the specified ID and data
const { data: updatedRule, error } = await updateRule(ruleId, data, options);

if (error) {
  console.error("Error updating the rule:", error);
} else {
  console.log("Updated rule:", updatedRule);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `ruleId` | Number | The ID of the rule to update.
| `data` | `ApiUpdateRulePayload` | The updated data for the rule. |
| `options?` | `AzionClientOptions`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionRule>>`| The updated rule object or error if the update failed. |


#### `deleteRule`

Deletes a rule.

**TypeScript example**:

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

// The ID of the rule to delete
const ruleId = 123;

// Optional parameters including debug mode
const options = { debug: true };

// Delete the rule with the specified ID
const { data: deletionConfirmation, error } = await deleteRule(ruleId, options);

if (error) {
  console.error("Error deleting the rule:", error);
} else {
  console.log("Rule deleted successfully:", deletionConfirmation);
}

```

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `ruleId` | Number | The ID of the rule to delete. |
| `options?` | `AzionClientOptions`| Optional parameters including debug mode. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `Promise<AzionApplicationResponse<AzionDeletedRule>>`| Confirmation of deletion or error if the operation failed. |

---