Purge cache

post
Purge cache API

https://api.imagekit.io/v1/files/purge
This will purge CDN and ImageKit.io internal cache.
Request
Response
Request
Headers
Authorization
required
string
base64 encoding of your_private_api_key: Note the colon in the end.
Body Parameters
url
required
string
The exact URL of the file to be purged. For example - https://ik.imageki.io/your_imagekit_id/rest-of-the-file-path.jpg
Response
200: OK
On success, you will receive a requestId which can be used to get the purge request status.
{
requestId : "598821f949c0a938d57563bd"
}

Response structure and status code

In case of error, you will get an error code along with the error message. On success, you will receive a 200 status code with the request ID returned in JSON-encoded response body.

requestId can be used to fetch the status of submitted purge request.

Limitations

Purge API has following limitations:

  • An account can issue a maximum of 1000 purge requests in a month. Please reach out to us at support@imagekit.io if you need to increase this limit.

  • Purge API doesn't accept wildcard in url. Please reach out to us at support@imagekit.io if you need to purge all images on a specific pattern.

Examples

Here are some example requests to understand the API usage.

cURL
Node.js
Python
PHP
cURL
curl -X POST "https://api.imagekit.io/v1/files/purge" \
-H "content-type: application/json" \
-u your_private_key: -d'
{
"url": "https://ik.imagekit.io/your_imagekit_id/default-image.jpg"
}
'
Node.js
var ImageKit = require("imagekit");
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
imagekit.purgeCache("https://ik.imagekit.io/your_imagekit_id/default-image.jpg", function(error, result) {
if(error) console.log(error);
else console.log(result);
});
Python
from imagekitio import ImageKit
imagekit = ImageKit(
private_key='your_public_api_key',
public_key='your_private_api_key',
url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/'
)
purge_cache = imagekit.purge_cache(file_url="https://ik.imagekit.io/your_imagekit_id/default-image.jpg")
print("Purge cache-", purge_cache)
PHP
use ImageKit\ImageKit;
$public_key = "your_public_api_key";
$your_private_key = "your_private_api_key";
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
$imageKit = new ImageKit(
$public_key,
$your_private_key,
$url_end_point
);
$purgeCache = $imageKit->purgeCacheApi(array(
"url" => "https://ik.imagekit.io/your_imagekit_id/default-image.jpg"
));
echo("File details : " . json_encode($purgeCache));