---
name: azion-clone-an-application-or-a-firewall
description: >-
  Copy an Application with its cache settings, Function Instances, and rules, or a Firewall with its Function Instances and rules, with one API v4 request.
---

# Clone an Application or a Firewall

You can clone an [Application](/en/documentation/platform/applications/) or a [Firewall](/en/documentation/platform/firewall/) with one `POST` request to the [Azion API](/en/documentation/devtools/api/) v4. To clone an Application from Azion Console instead, refer to [Clone an application](/en/documentation/guides/application-development/getting-started/clone-applications/). To clone one with the Azion CLI, refer to [Azion CLI clone](/en/documentation/devtools/cli/clone/). In Azion Console, the **Clone** row action of the **Firewalls** list clones a Firewall.

The examples clone an Application that holds a [cache setting](/en/documentation/platform/applications/cache/cache-settings/), a [Function Instance](/en/documentation/platform/applications/functions-instances/), two [request rules](/en/documentation/platform/applications/rules-engine/), and a response rule. They also clone a Firewall that holds a Function Instance and two request rules.

---

## Prerequisites

- A personal token. To create one, refer to [Manage personal tokens](/en/documentation/guides/platform/account-and-billing/personal-tokens/).
- `curl`, to call the API, and `jq`, to read IDs from the responses.
- The ID of the Application or the Firewall to clone.

---

## Clone an Application

The clone endpoint takes one required field, `name`: 1 to 100 characters that no other Application uses.

To clone the Application:

1. Store your token and the ID of the Application in shell variables. Replace the two values with your own:

   ```bash
   export AZION_API_TOKEN="[TOKEN VALUE]"
   APPLICATION_ID=<your-application-id>
   ```

2. Send a `POST` request to the clone endpoint of the Application. Replace `shop-production` with the name of your copy:

   ```bash
   curl --silent "https://api.azion.com/v4/workspace/applications/$APPLICATION_ID/clone" \
     --header "Authorization: Token $AZION_API_TOKEN" \
     --header 'Content-Type: application/json' \
     --data '{"name": "shop-production"}' \
   | tee application-clone.json
   ```

   The API answers `202`, and the response carries the new Application. This excerpt shows its ID and name:

   ```json
   {
     "state": "pending",
     "data": {
       "id": 1795022609,
       "name": "shop-production",
       ...
     }
   }
   ```

3. Store the ID of the copy:

   ```bash
   CLONE_ID=$(jq .data.id application-clone.json)
   ```

The account holds a new Application named `shop-production`, and `CLONE_ID` holds its ID.

A name that another Application already uses returns `400` with code `31000` and the title `Name Already In Use`. A body without `name` returns `400` with code `10059`.

A request reaches the copy only once the deployment of a [Workload](/en/documentation/platform/workloads/) sets that Application. To set it, refer to [Deployment](/en/documentation/platform/workloads/settings/#deployment).

---

## Check what the Application clone carries

The copy carries the cache settings, the Function Instances, and the request and response rules of the original, each with a new ID. The request rules of the copy point at the cache settings and Function Instances of the copy, not at those of the original.

To check the copy:

1. Store your token and the ID of the copy. Replace the two values with your own:

   ```bash
   export AZION_API_TOKEN="[TOKEN VALUE]"
   CLONE_ID=<your-clone-id>
   ```

2. List the cache settings of the copy:

   ```bash
   curl --silent "https://api.azion.com/v4/workspace/applications/$CLONE_ID/cache_settings?fields=id,name" \
     --header "Authorization: Token $AZION_API_TOKEN"
   ```

   The copy holds one cache setting, `static-assets`, under a new ID:

   ```json
   {
     "count": 1,
     ...
     "results": [
       {
         "id": 395192,
         "name": "static-assets"
       }
     ]
   }
   ```

3. List the Function Instances of the copy:

   ```bash
   curl --silent "https://api.azion.com/v4/workspace/applications/$CLONE_ID/functions?fields=id,name,function" \
     --header "Authorization: Token $AZION_API_TOKEN"
   ```

   The copy holds one Function Instance, `hello`, which runs the same Function as the original:

   ```json
   {
     "count": 1,
     ...
     "results": [
       {
         "id": 64958,
         "name": "hello",
         "function": 110776
       }
     ]
   }
   ```

4. List the request rules of the copy, with their behaviors:

   ```bash
   curl --silent "https://api.azion.com/v4/workspace/applications/$CLONE_ID/request_rules?fields=id,name,order,behaviors" \
     --header "Authorization: Token $AZION_API_TOKEN"
   ```

   Each request rule of the copy points at the cache setting or the Function Instance of the copy:

   ```json
   {
     "count": 2,
     ...
     "results": [
       {
         "id": 1551356,
         "name": "Cache images",
         "behaviors": [
           {
             "type": "set_cache_policy",
             "attributes": {
               "value": 395192
             }
           }
         ],
         "order": 0
       },
       {
         "id": 1551357,
         "name": "Run hello",
         "behaviors": [
           {
             "type": "run_function",
             "attributes": {
               "value": 64958
             }
           }
         ],
         "order": 1
       }
     ]
   }
   ```

5. List the response rules of the copy:

   ```bash
   curl --silent "https://api.azion.com/v4/workspace/applications/$CLONE_ID/response_rules?fields=id,name,order" \
     --header "Authorization: Token $AZION_API_TOKEN"
   ```

   The copy holds the response rule `Add header`:

   ```json
   {
     "count": 1,
     ...
     "results": [
       {
         "id": 1551358,
         "name": "Add header",
         "order": 0
       }
     ]
   }
   ```

The copied rules point at `395192` and `64958`, the cache setting and the Function Instance of the copy. In the original, the same cache setting and Function Instance keep their own IDs, `395191` and `64957`. A change to a cache setting or a rule of the copy leaves the original unchanged.

---

## Clone a Firewall

The clone endpoint of a Firewall takes one required field, `name`: 1 to 250 characters that no other Firewall uses.

To clone the Firewall:

1. Store your token and the ID of the Firewall in shell variables. Replace the two values with your own:

   ```bash
   export AZION_API_TOKEN="[TOKEN VALUE]"
   FIREWALL_ID=<your-firewall-id>
   ```

2. Send a `POST` request to the clone endpoint of the Firewall. Replace `shop-production-firewall` with the name of your copy:

   ```bash
   curl --silent "https://api.azion.com/v4/workspace/firewalls/$FIREWALL_ID/clone" \
     --header "Authorization: Token $AZION_API_TOKEN" \
     --header 'Content-Type: application/json' \
     --data '{"name": "shop-production-firewall"}' \
   | tee firewall-clone.json
   ```

   The API answers `202`, and the response carries the new Firewall:

   ```json
   {
     "state": "pending",
     "data": {
       "id": 104431,
       "name": "shop-production-firewall",
       "modules": {
         "ddos_protection": {
           "enabled": true
         },
         "functions": {
           "enabled": true
         },
         "network_protection": {
           "enabled": true
         },
         "waf": {
           "enabled": false
         }
       },
       ...
     }
   }
   ```

3. Store the ID of the copy:

   ```bash
   FIREWALL_CLONE_ID=$(jq .data.id firewall-clone.json)
   ```

4. List the Function Instances of the copy:

   ```bash
   curl --silent "https://api.azion.com/v4/workspace/firewalls/$FIREWALL_CLONE_ID/functions?fields=id,name,function" \
     --header "Authorization: Token $AZION_API_TOKEN"
   ```

   The copy holds one Function Instance, `passthrough`, which runs the same Function as the original:

   ```json
   {
     "count": 1,
     ...
     "results": [
       {
         "id": 23051,
         "name": "passthrough",
         "function": 110777
       }
     ]
   }
   ```

5. List the request rules of the copy, with their behaviors:

   ```bash
   curl --silent "https://api.azion.com/v4/workspace/firewalls/$FIREWALL_CLONE_ID/request_rules?fields=id,name,order,behaviors" \
     --header "Authorization: Token $AZION_API_TOKEN"
   ```

   The `run_function` rule of the copy points at the Function Instance of the copy:

   ```json
   {
     "count": 2,
     ...
     "results": [
       {
         "id": 170526,
         "name": "Block admin",
         "behaviors": [
           {
             "type": "deny"
           }
         ],
         "order": 0
       },
       {
         "id": 170525,
         "name": "Run passthrough",
         "behaviors": [
           {
             "type": "run_function",
             "attributes": {
               "value": 23051
             }
           }
         ],
         "order": 1
       }
     ]
   }
   ```

The account holds a new Firewall named `shop-production-firewall`, with copies of the rules and the Function Instances of the original. The copied `run_function` rule points at `23051`, the Function Instance of the copy.

A name that another Firewall already uses returns `400` with code `24002` and the title `Name Already In Use`. A body without `name` returns `400` with code `10059`.

The copy inspects requests only once a Workload's deployment sets that Firewall. To set it, refer to [Deployment](/en/documentation/platform/workloads/settings/#deployment).

---

## Next steps

- [Workload settings](/en/documentation/platform/workloads/settings.md#deployment): Set the copy as the Application or the Firewall of a Workload's deployment.
- [Troubleshoot Azion API](/en/documentation/devtools/api/troubleshooting.md): Causes and fixes for the 400, 401, 404, and 405 responses of the API v4.
