Create a purge request

Update time: 2025-08-13 18:17:46

Create a purge request to force a refresh of the content stored in the CDN Pro cache servers. You may wish to do this if you just updated content on your origin server and want visitors to see the changes right away rather than wait for the updates to propagate according to the schedule defined in your property configuration.

  • Limit of request rate per user: 300/5min
  • Applicable Products: CDN Pro
For API authentication details, please refer to: API Authentication Overview

Request

Body Params

NameDescription
nameString
A description of the purge request.
fileUrlsList
URLs of files to purge. File URLs should not contain the asterisk character, '*'. If a directory or filename in a URL includes a percent character, '%', be sure to encode it. A URL can be up to 2048 characters.
fileHeadersList
If a file's cache key depends on request headers, you can specify the header values that are applicable to purge one version of the cached file. The same set of header values will apply to all entries in fileUrls.
nameString
HTTP header name.
valueString
Value of an HTTP header.
dirUrlsList
<= 20 items URLs to purge. URLs must begin with http:// or https:// and can be up to 2048 characters. Use the '*' character to purge multiple files or directories. If a URL has multiple sets of asterisk characters, only the last '*' or '**' will be treated as a wildcard. Other instances of '*' earlier in the URL will be treated as the literal character '*'.
ExampleDescription
http://test.domain2.com/mydirPurge all variations of a single directory, but not its subdirectories or files. Variations may exist if custom cache keys are used.
http://test.domain2.com/mydir/**Purge all files and subdirectories whose cache key begins with http://test.domain2.com/mydir/.
http://test.domain2.com/mydir/*Purge all files, but not subdirectories, within a directory.
http://test.domain2.com/mydir/*.jpgPurge all cache entries ending with the .jpg file extension. Subdirectories of http://test.domain2.com/mydir/ are not purged.
http://test.domain2.com/mydir/a*Purge all files, but not subdirectories, that start with the letter 'a'.
http://test.domain2.com/mydir/a**Purge all files and subdirectories that start with the letter 'a'.
http://test.domain2.com/mydir/a.jpgPurge all variations of 'a.jpg'. Variations may exist if custom cache keys are used.
http://test.domain2.com/my**jpgPurge all entries whose cache key begins with http://test.domain2.com/my and ends with the suffix jpg. The '**' can match anything in the path including additional subdirectories. For example, http://test.domain2.com/mydirectory/picture.jpg would be purged.
If a directory or filename in a URL includes a percent character, '%', be sure to encode it.
regexPatternsList
<= 2 items Regular expression patterns used to match the cache key. Each must begin with the following format: {scheme}://{hostname}/. {scheme} can be http, https, or any, which matches any scheme. Example: https://test.domain.com/my.*\.(jpg|png)\?q=
For performance considerations, the following restrictions apply: The regular expression pattern following the hostname can be up to 126 characters. It can consist of up to two unlimited quantifiers ('*', '+', or ',}'). The upper limit on a quantifier cannot be more than 59, for example, {1,59}
actionString
Enum: delete invalidate Default: invalidate This controls whether cached files and directories should be removed altogether from the CDN Pro servers (delete) or flagged as invalid (invalidate).
*targetString
Enum: staging production Specify if the purge request applies to the staging or production environment.
webhookString
ID of a webhook to call when the purge task completes.

Response

Response Header

NameDescription
LocationString
Returns a URL pointing to the new purge task created, if the request is accepted. The URL contains the ID of the new purge task.
URL format: {scheme}://{domain}/cdn/purges/{purgeId} Example URL: https://api.example.com/cdn/purges/5dca2205f9e9cc0001df7b33

Error code

Error code(code)Description(message)HTTP statusSemantic
InvalidPurgeUrlThe host 'test.domain.info' has not been deployed in the 'production' environment.400The host 'test.domain.info' has not been deployed in the 'production' environment.
InvalidPurgeUrlThe purge URL 'http://domain.info/newfile[1]{tes`|t^}p.png' is invalid. Special letters need to be encoded.400The purge URL 'http://domain.info/newfile[1]{tes`|t^}p<u>.png' is invalid. Special letters need to be encoded.
InvalidPurgeUrlThe purge URL 'http://domain.info/i/image/gallery/123%abc.jpg' is invalid. Special letters need to be encoded.400The purge URL 'http://domain.info/i/image/gallery/123%abc.jpg' is invalid. Special letters need to be encoded.

Example

201
400
201
Request example
Copy Copy success
#!/bin/bash
username="example_username"
apiKey="example_apiKey"
date=`env LANG="en_US.UTF-8" date -u "+%a, %d %b %Y %H:%M:%S GMT"`
password=`echo -en "$date" | openssl dgst -sha1 -hmac $apiKey -binary | openssl enc -base64`
curl -i --url "https://api.cdnetworks.com/cdn/purges" \
-X "POST" \
-u "$username:$password" \
-H "Date: $date" \
-H "Accept: application/json" \
-d '{
  "fileUrls": [
    "http://domain.info/i/image/gallery/123.jpg",
    "http://test.domain2.com/2.txt?q1=1&q2=3"
  ],
  "fileHeaders": [
    {
      "name": "customheader1",
      "value": "test1"
    },
    {
      "name": "customheader2",
      "value": "test2"
    }
  ],
  "action": "invalidate",
  "target": "production"
}'
Response example
Copy Copy success
HTTP/1.1 201 Created
Date: Mon, 11 Aug 2025 06:15:25 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 0
Location: https://open.chinanetcenter.com/cdn/purges/5dca2205f9e9cc0001df7b33
Is the content of this document helpful to you?
Yes
I have suggestion
Submitted successfully! Thank you very much for your feedback, we will continue to strive to do better!