---
name: azion-change-one-setting-with-a-patch-request
description: >-
  Change one setting of an Azion API v4 resource with PATCH, or replace the whole resource with PUT and keep the settings you did not change.
---

# Change one setting with a PATCH request

You can change one setting of an [Azion API](/en/documentation/devtools/api/) v4 resource with a `PATCH` request. `PATCH` keeps every setting you leave out of the body. A `PUT` request replaces the whole resource instead. Most API v4 endpoints for a single resource take both methods.

The examples change a [cache setting](/en/documentation/platform/applications/cache/cache-settings/) of an [Application](/en/documentation/platform/applications/).

---

## 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 edit the JSON body of a `PUT` request.
- An Application with a cache setting. To create one, refer to [Create a cache setting](/en/documentation/guides/application-performance/cache-and-purge/tune-cache-settings/).

---

## Find the ID of the cache setting

The path of one cache setting in the API carries two IDs: the Application's and the cache setting's.

To find the ID of the cache setting:

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. List the cache settings of the Application. The `fields` parameter limits each result to its ID and name:

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

   ```json
   {
     "count": 1,
     "total_pages": 1,
     "page": 1,
     "page_size": 10,
     "next": null,
     "previous": null,
     "results": [
       {
         "id": 395100,
         "name": "static-assets"
       }
     ]
   }
   ```

3. Store the `id` of the cache setting you want to change. Replace the value with that `id`:

   ```bash
   CACHE_SETTING_ID=<your-cache-setting-id>
   ```

`APPLICATION_ID` and `CACHE_SETTING_ID` hold the two IDs of the cache setting's path.

---

## Change one setting with PATCH

A `PATCH` body carries only the settings to change. A setting inside a nested object, such as `max_age` inside `browser_cache`, changes alone too.

`browser_cache.max_age` sets the browser cache time only while `browser_cache.behavior` is `override`. With `honor`, Azion forwards to the browser the `Cache-Control` and `Expires` headers that your origin sends.

Send a `PATCH` request that sets the browser cache time to 600 seconds. Replace the three values with your own:

```bash
export AZION_API_TOKEN="[TOKEN VALUE]"
APPLICATION_ID=<your-application-id>
CACHE_SETTING_ID=<your-cache-setting-id>
curl --silent --request PATCH "https://api.azion.com/v4/workspace/applications/$APPLICATION_ID/cache_settings/$CACHE_SETTING_ID" \
  --header "Authorization: Token $AZION_API_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{"browser_cache": {"max_age": 600}}'
```

The response carries the whole cache setting. This excerpt shows `browser_cache` and `modules.cache`, the object that sets how long Azion keeps a copy of a response:

```json
{
  "state": "executed",
  "data": {
    "id": 395100,
    "name": "static-assets",
    "browser_cache": {
      "behavior": "override",
      "max_age": 600
    },
    "modules": {
      "cache": {
        "behavior": "override",
        "max_age": 86400,
        ...
      },
      ...
    },
    ...
  }
}
```

The browser cache time is 600 seconds, because `browser_cache.behavior` is `override` in this cache setting. The `behavior` of `browser_cache` and the `modules.cache` settings keep their values.

---

## Replace the cache setting with PUT

A `PUT` body must carry every setting you want to keep, so you build it from a saved copy of the cache setting.

With `override` in `modules.cache.behavior`, `modules.cache.max_age` replaces the `Cache-Control` and `Expires` headers your origin sends. Otherwise, with `honor`, Azion uses `max_age` only when your origin sends neither header.

> **Caution**
>
> A setting that a `PUT` body leaves out returns to its default value. On a cache setting, a `PUT` body with only `name` and `browser_cache` sets `modules.cache` to `"behavior": "honor"` and `"max_age": 60`. A body without a required field, such as `name`, returns `400` with code `10059`.

To replace the cache setting:

1. Save the current cache setting to a file. Replace the three values with your own:

   ```bash
   export AZION_API_TOKEN="[TOKEN VALUE]"
   APPLICATION_ID=<your-application-id>
   CACHE_SETTING_ID=<your-cache-setting-id>
   curl --silent "https://api.azion.com/v4/workspace/applications/$APPLICATION_ID/cache_settings/$CACHE_SETTING_ID" \
     --header "Authorization: Token $AZION_API_TOKEN" \
   > cache-setting.json
   ```

   The command prints nothing. The `cache-setting.json` file holds the cache setting inside `data`.

2. Change the copy and send it in a `PUT` request. This `jq` filter sets `modules.cache.max_age` to 3,600 seconds and passes everything else unchanged:

   ```bash
   jq '.data | .modules.cache.max_age = 3600' cache-setting.json \
   | curl --silent --request PUT "https://api.azion.com/v4/workspace/applications/$APPLICATION_ID/cache_settings/$CACHE_SETTING_ID" \
     --header "Authorization: Token $AZION_API_TOKEN" \
     --header 'Content-Type: application/json' \
     --data @-
   ```

   ```json
   {
     "state": "executed",
     "data": {
       "id": 395100,
       "name": "static-assets",
       "browser_cache": {
         "behavior": "override",
         "max_age": 600
       },
       "modules": {
         "cache": {
           "behavior": "override",
           "max_age": 3600,
           ...
         },
         ...
       },
       ...
     }
   }
   ```

`modules.cache.max_age` is 3,600 seconds, and every other setting of the copy is unchanged. You do not need to remove the `id` and `created_at` fields of the copy: the `PUT` request accepts them.

---

## Next steps

- [Troubleshoot Azion API](/en/documentation/devtools/api/troubleshooting.md): Causes and fixes for the 400, 401, 404, and 405 responses of the API v4.
- [Cache settings](/en/documentation/platform/applications/cache/cache-settings.md): Every setting of a cache setting and its default value.
