|
| 1 | +--- |
| 2 | +title: Common API calls |
| 3 | +pcx_content_type: configuration |
| 4 | +sidebar: |
| 5 | + order: 5 |
| 6 | +head: |
| 7 | + - tag: title |
| 8 | + content: Common API calls | Custom Error Assets |
| 9 | +--- |
| 10 | + |
| 11 | +The following sections provide examples of common API calls for managing custom error assets at the zone level. |
| 12 | + |
| 13 | +To perform the same operations at the account level, use the corresponding account-level API endpoints. |
| 14 | + |
| 15 | +### Create a custom error asset |
| 16 | + |
| 17 | +The following `POST` request creates new a custom error asset in a zone based on the provided URL: |
| 18 | + |
| 19 | +```bash |
| 20 | +curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_pages/assets" \ |
| 21 | +--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ |
| 22 | +--json '{ |
| 23 | + "name": "500_error_template", |
| 24 | + "description": "Standard 5xx error template page", |
| 25 | + "url": "https://example.com/errors/500_template.html" |
| 26 | +}' |
| 27 | +``` |
| 28 | + |
| 29 | +```json output |
| 30 | +{ |
| 31 | + "result": { |
| 32 | + "name": "500_error_template", |
| 33 | + "description": "Standard 5xx error template page", |
| 34 | + "url": "https://example.com/errors/500_template.html", |
| 35 | + "last_updated": "2025-02-10T11:36:07.810215Z", |
| 36 | + "size_bytes": 2048 |
| 37 | + }, |
| 38 | + "success": true |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +To create an asset at the account level, use the account-level endpoint: |
| 43 | + |
| 44 | +```txt |
| 45 | +https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/custom_pages/assets |
| 46 | +``` |
| 47 | + |
| 48 | +### List custom error assets |
| 49 | + |
| 50 | +The following `GET` request retrieves a list of custom error assets configured in the zone: |
| 51 | + |
| 52 | +```bash |
| 53 | +curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_pages/assets" \ |
| 54 | +--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" |
| 55 | +``` |
| 56 | + |
| 57 | +```json output |
| 58 | +{ |
| 59 | + "result": [ |
| 60 | + { |
| 61 | + "name": "500_error_template", |
| 62 | + "description": "Standard 5xx error template page", |
| 63 | + "url": "https://example.com/errors/500_template.html", |
| 64 | + "last_updated": "2025-02-10T11:36:07.810215Z", |
| 65 | + "size_bytes": 2048 |
| 66 | + } |
| 67 | + // ... |
| 68 | + ], |
| 69 | + "success": true, |
| 70 | + "errors": [], |
| 71 | + "messages": [], |
| 72 | + "result_info": { |
| 73 | + "count": 2, |
| 74 | + "page": 1, |
| 75 | + "per_page": 20, |
| 76 | + "total_count": 2, |
| 77 | + "total_pages": 1 |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +To retrieve a list of assets at the account level, use the account-level endpoint: |
| 83 | + |
| 84 | +```txt |
| 85 | +https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/custom_pages/assets |
| 86 | +``` |
| 87 | + |
| 88 | +### Update a custom error asset |
| 89 | + |
| 90 | +The following `PUT` request updates the URL of an existing custom error asset at the zone level named `500_error_template`: |
| 91 | + |
| 92 | +```bash |
| 93 | +curl --request PUT \ |
| 94 | +"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_pages/assets/500_error_template" \ |
| 95 | +--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ |
| 96 | +--json '{ |
| 97 | + "description": "Standard 5xx error template page", |
| 98 | + "url": "https://example.com/errors/500_new_template.html" |
| 99 | +}' |
| 100 | +``` |
| 101 | + |
| 102 | +```json output |
| 103 | +{ |
| 104 | + "result": { |
| 105 | + "name": "500_error_template", |
| 106 | + "description": "Standard 5xx error template page", |
| 107 | + "url": "https://example.com/errors/500_new_template.html", |
| 108 | + "last_updated": "2025-02-10T13:13:07.810215Z", |
| 109 | + "size_bytes": 3145 |
| 110 | + }, |
| 111 | + "success": true |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +You can update the asset description and URL. You cannot update the asset name after creation. |
| 116 | + |
| 117 | +If you provide the same URL when updating an asset, Cloudflare will fetch the URL again, along with its resources. |
| 118 | + |
| 119 | +To update an asset at the account level, use the account-level endpoint: |
| 120 | + |
| 121 | +```txt |
| 122 | +https://api.cloudflare.com/client/v4/accounts/{account_id}/custom_pages/assets/{asset_name} |
| 123 | +``` |
| 124 | + |
| 125 | +### Get a custom error asset |
| 126 | + |
| 127 | +The following `GET` request retrieves the details of an existing custom error asset at the zone level named `500_error_template`: |
| 128 | + |
| 129 | +```bash |
| 130 | +curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_pages/assets/500_error_template" \ |
| 131 | +--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" |
| 132 | +``` |
| 133 | + |
| 134 | +```json output |
| 135 | +{ |
| 136 | + "result": { |
| 137 | + "name": "500_error_template", |
| 138 | + "description": "Standard 5xx error template page", |
| 139 | + "url": "https://example.com/errors/500_new_template.html", |
| 140 | + "last_updated": "2025-02-10T13:13:07.810215Z", |
| 141 | + "size_bytes": 3145 |
| 142 | + }, |
| 143 | + "success": true |
| 144 | +} |
| 145 | +``` |
| 146 | + |
| 147 | +To retrieve an asset at the account level, use the account-level endpoint: |
| 148 | + |
| 149 | +```txt |
| 150 | +https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/custom_pages/assets/$ASSET_NAME |
| 151 | +``` |
| 152 | + |
| 153 | +### Delete a custom error asset |
| 154 | + |
| 155 | +The following `DELETE` request deletes an existing custom error asset at the zone level named `500_error_template`: |
| 156 | + |
| 157 | +```bash |
| 158 | +curl --request DELETE \ |
| 159 | +"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_pages/assets/500_error_template" \ |
| 160 | +--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" |
| 161 | +``` |
| 162 | + |
| 163 | +If the request is successful, the response will have a `204` HTTP status code. |
| 164 | + |
| 165 | +To delete an asset at the account level, use the account-level endpoint: |
| 166 | + |
| 167 | +```txt |
| 168 | +https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/custom_pages/assets/$ASSET_NAME |
| 169 | +``` |
0 commit comments