> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloud.aptranet.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update CDN configuration through the API

> Read a distribution's cache settings, change one value, submit the complete configuration, and verify the result.

CDN configuration endpoints accept the complete configuration for one area, such as cache or TLS. Sending only the field you want to change can fail validation or reset other settings.

This example changes an existing edge-cache TTL to 3,600 seconds while preserving the other cache fields. Use a non-production distribution first.

## Before you begin

* Complete [your first API request](/api-reference/first-request); the Bash examples use the same credential variables.
* Have permission to read and modify the distribution's cache configuration.
* Install `jq` for JSON editing and use curl 7.76 or later for `--fail-with-body`.
* Choose an existing distribution in the key's project. The examples use ID `73`; replace it in every URL.
* Confirm edge caching is already enabled with `controlled_by: "cdn"`. This example does not change who controls freshness.

## 1. Read and save the current configuration

Run these commands in a private working directory. The files contain distribution settings, not API credentials.

```bash theme={"system"}
curl --silent --show-error --fail-with-body \
  --request GET \
  --url "https://cloud.aptranetservices.com/cloud-cdn/distributions/configurations/cache?distribution=73" \
  --header "Authorization: Bearer $APTRANET_ACCESS_KEY" \
  --header "Aptranet-Secret: $APTRANET_SECRET" \
  --header "Accept: application/json" \
  --output cache-before.json
```

Continue only if the request succeeded and `cache-before.json` contains the cache configuration rather than an error document. Keep the original file for comparison and rollback.

## 2. Prepare the change

This command checks the required cache mode before changing the TTL:

```bash theme={"system"}
jq -e '
  if .edge_cache.enabled == true and .edge_cache.controlled_by == "cdn"
  then .edge_cache.ttl = 3600
  else error("Use an enabled, CDN-controlled edge cache for this example")
  end
' cache-before.json > cache-after.json

diff -u cache-before.json cache-after.json
```

Stop if `jq` fails. A successful `diff` comparison with changes exits with code `1`; review the output and confirm that the TTL is the only intended change. Formatting may also differ.

## 3. Submit the full document

```bash theme={"system"}
curl --silent --show-error --fail-with-body \
  --request PUT \
  --url "https://cloud.aptranetservices.com/cloud-cdn/distributions/configurations/cache?distribution=73" \
  --header "Authorization: Bearer $APTRANET_ACCESS_KEY" \
  --header "Aptranet-Secret: $APTRANET_SECRET" \
  --header "Content-Type: application/json" \
  --data-binary @cache-after.json
```

A successful update does not mean previously cached objects were removed. Use a targeted [purge](/cloud-cdn/purge-and-prefetch) if you also need to invalidate existing content.

## 4. Read back and test delivery

Repeat the GET request from step 1 with `--output cache-verified.json`. Compare its `edge_cache` fields with the intended state, then request a representative public file through the distribution.

The saved configuration verifies the control-plane change. Inspect actual responses and [request logs](/cloud-cdn/logs) to verify delivery behavior.

## Recover from a failed or unwanted change

| Situation | Action |
| - | - |
| Validation fails | Read the error body and correct the complete document before resubmitting |
| The request times out | GET the configuration first; the update may already have applied |
| Another operator changed the distribution | Read the latest state and reconcile both changes before writing again |
| You need to undo this change | Review `cache-before.json`, then submit it with the same PUT request |

Restoring the saved document replaces all settings in that configuration area. Check for changes made by other operators before restoring it. The API does not document a general conditional-write or idempotency-key mechanism.

See [request conventions](/api-reference/request-conventions) for other configuration areas and [caching](/cloud-cdn/caching) for the meaning of each control.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.