Delivery
Custom pages
Replace the pages the CDN shows to visitors with your own text, set the captcha colors and put hosts in maintenance.
Every domain has nine pages that the CDN serves itself. Here you read them, replace their text with your own, put the default back, and change the customize settings: the captcha colors and the maintenance mode. The paths start with /v2/cdn/custom_pages/{domain_public_id}/, where the id is the public id of the domain, taken from the domains list.
The examples on this page use these shell variables:
export DIAMWALL_API_KEY="your key"export PAGES="https://api.diamwall.com/v2/cdn/custom_pages/your-domain-public-id"Custom pages are part of the Business and Enterprise plans. A domain on any other plan answers 403 FEATURE_NOT_AVAILABLE on every call here.
The nine pages
Section titled “The nine pages”The collection always has the same nine pages. Their ids are fixed:
5s, unusual, 502, 504, denied, oops, dwaf, maintenance, bot-blocked
A page is never created and never gone. It is either the default page, or a page the domain has a text of its own for. Any other id answers 400 INVALID_REQUEST and names page_id.
Two ETags, two kinds of write
Section titled “Two ETags, two kinds of write”Every write has to prove it saw the latest state, with the ETag of a read sent back in If-Match, exactly as it came. There are three different ETags here, and they are not interchangeable:
| You want to | Read first | Then send its ETag to |
|---|---|---|
| Write or remove the text of a page | GET .../pages/{page_id}/content/ |
PUT or DELETE .../pages/{page_id}/content/ |
| Delete a page from the collection | GET .../pages/ or GET .../pages/{page_id}/ |
DELETE .../pages/{page_id}/ |
| Edit the colors or the maintenance mode | GET .../settings/customize/ |
PATCH .../settings/customize/ |
A write without If-Match answers 428. A write whose ETag is out of date answers 412 REVISION_MISMATCH: read again and retry. An If-Match that is not the ETag as it came (a weak one, *, a list, no quotes) answers 400 INVALID_PRECONDITION.
List the pages
Section titled “List the pages”curl "$PAGES/pages/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:0d1e6041d11f...", "consistency": "verified", "publication": { "status": "verified", "rollout": "unknown" }, "data": { "items": [ { "id": "5s", "metadata": { "state": "resolved", "value": { "is_custom": false, "byte_size": 38 } } }, { "id": "502", "metadata": { "state": "resolved", "value": { "is_custom": true, "byte_size": 21 } } } ], "page": { "limit": 50, "next_cursor": null, "total": 9 } }}metadata.value.is_customistruewhen the domain has its own text for the page, andfalsewhen the page is the default one.metadata.value.byte_sizeis the size of the page in bytes. When it is missing, the size is unavailable. It is never zero.- A
metadatawhosestateisunknownhas novalue. Treat the page as unavailable, never as a default page. - The list holds no HTML. The text is read through its own endpoint.
limitgoes from 1 to 100, and is 50 without it. To read the next page, senddata.page.next_cursorback ascursor, until it isnull. If the collection changes between two pages, the next page answers409 CURSOR_STALE. Start again from the first page.- No other query parameter is accepted.
Read one page
Section titled “Read one page”curl "$PAGES/pages/502/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"The page is under data, with the same id and metadata as in the list.
The bot-blocked page has two more fields in metadata.value:
| Field | Meaning |
|---|---|
available |
true: the page is ready to be written. false: a write of its text is refused, and reason says why in one word. Its text can still be read and removed. When the field is missing, the CDN did not say. That is not false. |
applied |
Always unknown. Saving the page is never a confirmation that it is served everywhere. |
Delete a page
Section titled “Delete a page”Deleting a page removes the domain’s own text of it, so the CDN serves the default page again. The page stays in the collection. The request takes no body, and its If-Match is the ETag of the list or of one page:
ETAG=$(curl -s -o /dev/null -D - "$PAGES/pages/502/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')
curl -X DELETE "$PAGES/pages/502/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "If-Match: $ETAG"The answer has an operation object with the id of the page, and a new ETag header for the next write to the collection. It holds no page: read the page to see what it is now.
Removing the text has the same effect. The two calls differ only in the ETag they take.
Page text
Section titled “Page text”Read the text
Section titled “Read the text”curl -i "$PAGES/pages/502/content/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "data": { "page": "502", "content": "<!doctype html>\n<html>\n <body>\n <h1>We will be right back</h1>\n </body>\n</html>\n", "publication": "verified" }}data.contentis the whole text of the page as the CDN serves it: the domain’s own text when it has one, otherwise the text of the default page. To know which of the two it is, readis_customof the page.- The text always comes as a string inside JSON, never as
text/html. A request whoseAcceptheader allows no JSON answers406 NOT_ACCEPTABLE. data.publicationisverifiedorunverified. Averifiedanswer comes with anETagheader. Anunverifiedanswer is a preview with noETag, so there is nothing to send inIf-Match: do not write or remove the text from it.- For the
dwafpage, a block page setting that cannot be read answers409 INVALID_STATE. The text is unavailable. Do not show an empty or default page in its place.
Write the text
Section titled “Write the text”The body is the text itself, not JSON. Read the text first to get its ETag, then send the new text:
ETAG=$(curl -s -o /dev/null -D - "$PAGES/pages/502/content/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')curl -X PUT "$PAGES/pages/502/content/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: text/html" \ -H "If-Match: $ETAG" \ --data-binary @502.htmlcurl -X PUT "$PAGES/pages/502/content/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: text/html; charset=utf-8" \ -H "If-Match: $ETAG" \ --data-binary '<!doctype html><html> <body> <h1>We will be right back</h1> </body></html>'Use --data-binary, so curl sends the file byte for byte. The text is stored exactly as you send it: nothing is trimmed, rewritten or added.
| Rule | If you break it |
|---|---|
Content-Type is text/html or text/plain, with no charset or with charset=utf-8 |
415 UNSUPPORTED_MEDIA_TYPE. This includes application/json. |
| The body is not empty | 400 INVALID_REQUEST |
| The text is valid UTF-8 with no NUL character | 400 INVALID_REQUEST, with content in fields |
At most 1048576 bytes, or 65536 bytes for the dwaf page |
413 PAYLOAD_TOO_LARGE |
The answer is 200 with revision, consistency and publication, and nothing of the page. Read the text again before your next write, and use the ETag of that read.
Remove the text
Section titled “Remove the text”Removing the text puts the default page back. The request takes no body, and its If-Match is the ETag of a read of the text:
curl -X DELETE "$PAGES/pages/502/content/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "If-Match: $ETAG"For bot-blocked this is the only way to put the default page back. It does not depend on available.
Captcha colors and maintenance
Section titled “Captcha colors and maintenance”Read the settings
Section titled “Read the settings”curl -i "$PAGES/settings/customize/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:66db0466f581...", "consistency": "verified", "publication": { "status": "verified", "rollout": "unknown" }, "data": { "captcha_colors": { "state": "resolved", "value": { "mclrdw": "0c4a56", "sclrdw": "2ea8c1" } }, "maintenance_declared": { "state": "resolved", "value": { "all": false, "hosts": ["www.example.com", "shop.example.com"] } }, "maintenance_runtime": { "state": "resolved", "value": { "all": false, "hosts": [] } } }}| Field | What it holds |
|---|---|
captcha_colors |
mclrdw, the main color, and sclrdw, the secondary one. Each is six hexadecimal digits, without #. |
maintenance_declared |
The maintenance mode as it is set: all and hosts. This is what an edit writes. |
maintenance_runtime |
Read-only. The maintenance mode as the CDN read it. It does not confirm that every location applies it. |
How to read maintenance_declared.value:
all |
hosts |
Meaning |
|---|---|---|
true |
empty | Every host of the domain is in maintenance. |
false |
a list | Only the listed hosts are in maintenance. |
false |
empty | No host is in maintenance. |
The answer does not list the hosts a domain has. Take them from its DNS records.
Change the settings
Section titled “Change the settings”The body holds captcha_colors, maintenance or both, and no other field. A field you leave out keeps its value. Read the settings first to get the ETag:
ETAG=$(curl -s -o /dev/null -D - "$PAGES/settings/customize/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')curl -X PATCH "$PAGES/settings/customize/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "captcha_colors": { "mclrdw": "112233", "sclrdw": "e94560" } }'curl -X PATCH "$PAGES/settings/customize/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "maintenance": { "all": false, "hosts": ["www.example.com", "shop.example.com"] } }'curl -X PATCH "$PAGES/settings/customize/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "maintenance": { "all": true, "hosts": [] } }'curl -X PATCH "$PAGES/settings/customize/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "maintenance": { "all": false, "hosts": [] } }'The answer is the settings as they are after the edit, in the same form as the read, with a new ETag header for your next edit.
The rules of the body:
captcha_colorshas at least one ofmclrdwandsclrdw. Each is exactly six hexadecimal digits, without#. Upper and lower case are both accepted, and the answer shows the color in lower case.maintenancealways has bothallandhosts.allis a JSON boolean, not"true"or1.hostsis a list of at most 1000 hostnames of this domain, each 1 to 253 characters, none repeated. It is empty whenallistrue.- The body is at most 32768 bytes.
- An empty body,
{}, answers400 NO_CHANGES.
A color edit answers 409 INVALID_STATE when the domain has no usable pair of colors to change. Nothing is written. This goes with a captcha_colors whose state is unknown: do not offer color editing until the read answers a pair.
When a write is not confirmed
Section titled “When a write is not confirmed”Some answers to a write do not tell you whether it was made. Do not send the request again blindly after any of them. Read the page (its item and its text) or the settings again, compare with what you meant to write, and only then decide. Each comes with a request_id to quote to support.
| Status | Code | What it means |
|---|---|---|
503 |
WRITE_VERIFICATION_FAILED |
Something was written, and reading it back did not confirm it. It is not a success and not a refusal. |
503 |
PUBLICATION_FAILED |
Settings only. The change could not be published and verified. A rollback is attempted, with no promise that it worked. |
| varies | FILE_SERVER_V2_ERROR |
An answer this API has no code of its own for. The write may have been refused, or made. |
503 RUNTIME_UNAVAILABLE on a write of a text is different: the text could not be checked right now and the page was not changed. Nothing in your request is wrong. Wait, then send the same request again with the same If-Match.
Limits and permissions
Section titled “Limits and permissions”- Plan. Business and Enterprise only. Any other plan answers
403 FEATURE_NOT_AVAILABLE, withdetails.feature(custom_pages) anddetails.plan. The owner of the domain gets the same answer. - Credits. Each domain has a budget of 3000 credits a minute, shared by everyone who calls the API for that domain. Every call here costs 8 credits. A request that is refused before it reaches the CDN, such as a wrong
page_id, a missingIf-Matchor a text that is too large, spends none. - Out of credits. The call answers
429 TOO_MANY_REQUESTS, with the wait in theRetry-Afterheader. - Size. A text holds at most 1048576 bytes, or 65536 bytes for the
dwafpage. A settings body holds at most 32768 bytes and 1000 hosts. - Permissions. They are separate, and one does not include another:
| Action | Permission on the domain |
|---|---|
| Read the pages, a text or the settings | pages.view |
| Write the text of a page | pages.create |
| Change the colors or the maintenance mode | pages.edit |
| Delete a page or remove its text | pages.delete |
pages.edit alone does not allow writing a text, and pages.create alone does not allow removing one.
Errors you are likely to see
Section titled “Errors you are likely to see”| Status | Code | What happened |
|---|---|---|
400 |
INVALID_REQUEST |
A field is wrong: a page_id that is not one of the nine, a text that is empty or not valid UTF-8, a color, a host. The answer names it in fields. |
400 |
NO_CHANGES |
A settings edit was sent with {}. |
400 |
INVALID_PRECONDITION |
If-Match is not the ETag exactly as it came. |
403 |
FEATURE_NOT_AVAILABLE |
The plan of the domain has no custom pages. |
404 |
CUSTOM_PAGE_NOT_FOUND, RESOURCE_ITEM_NOT_FOUND |
The CDN does not know that page. Nothing was read or written. |
404 |
SETTINGS_GROUP_NOT_FOUND |
The settings are unavailable for this domain. This does not mean that maintenance is off. |
406 |
NOT_ACCEPTABLE |
The Accept header allows no JSON. Send Accept: application/json, or no Accept header. |
409 |
CURSOR_STALE |
The collection changed while you were paging. Start from the first page. |
409 |
INVALID_STATE |
The change was refused for the state the settings or the domain are in, or the text of the dwaf page cannot be read. Nothing was written. |
412 |
REVISION_MISMATCH |
What you are writing changed since your read. Read again and retry. |
413 |
PAYLOAD_TOO_LARGE |
The text is above the size limit of the page. |
415 |
UNSUPPORTED_MEDIA_TYPE |
A text was sent as something other than text/html or text/plain in UTF-8, or a settings body was not sent as JSON. |
428 |
PRECONDITION_REQUIRED |
The If-Match header is missing. |
429 |
TOO_MANY_REQUESTS |
The domain is out of credits for now. |
503 |
RUNTIME_UNAVAILABLE |
The CDN cannot check a text right now. The page was not changed. |
503 |
WRITE_VERIFICATION_FAILED, PUBLICATION_FAILED |
The write is not confirmed. See When a write is not confirmed. |
The errors that come from the key itself, such as API_KEY_IP_NOT_ALLOWED, are on the Errors page.
All Custom pages endpoints
Section titled “All Custom pages endpoints”Each row opens the endpoint in the API reference, with every parameter, rule and response.
Loading the endpoints...