API to purge file cache from Spaces CDN after file update

I can’t find a non-manual way to purge the cache of a file in the CDN after I update it in Spaces. I feel like this is a common task but I can’t find any documentation on it besides the one telling you how to do it manually through DO’s website.

How can we purge the cache of a file after an update through an API?

FYI I’m updating files through the aws-sdk S3 API.

Show comments

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
April 10, 2019
Accepted Answer

Clarifying @jarland’s answer a bit: The Spaces API itself does not have support for purging the CDN’s cache, but the DigitalOcean platform API does. The Spaces API was designed to emulate the AWS S3 API so that developers could use it as a drop-in replacement for S3 existing projects. Spaces-specific functionality like the builtin CDN are not part of the S3 API but are support in the DigitalOcean API.

First you’ll need to find the ID of you CDN endpoint. You can do that by listing your CDN endpoints using:

curl -X GET -H "Content-Type: application/json" \
    -H "Authorization: Bearer $API_TOKEN" \

Then you can purge the cache with:

curl -X DELETE -H "Content-Type: application/json" \
    -H "Authorization: Bearer $API_TOKEN" \
    -d '{"files": ["*"]}' \

That command would purge the entire cache, but you could list specific files as well.

The DigitalOcean CLI, doctl, supports these as well:

To list the CDN endpoints run:

doctl compute cdn ls

And to purge the cache, run:

doctl compute cdn flush <CDN_ENDPOINT_ID> --files [*]

Find the full API reference docs here:

DigitalOcean Employee
DigitalOcean Employee badge
April 10, 2019


Great question. To purge the cache you would need to go through the control panel, but this is probably not the ideal method for automation. Instead, you should focus on the TTL. This document will give you a bit more insight into that:

You can set the TTL for the whole space or individual files (whole space being a bit easier). Once TTL is reached, the CDN should refresh it’s cache.


Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Me too … looking for a similar solution!