From 68dd5c5b6b6fdb00be58f14693b4ee9fbf867b1e Mon Sep 17 00:00:00 2001 From: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> Date: Wed, 26 Mar 2025 17:16:31 +0000 Subject: [PATCH 1/8] Update compression rules examples --- .../examples/disable-all-brotli.mdx | 36 ++++++++--------- .../examples/disable-compression-avif.mdx | 37 ++++++++---------- .../examples/enable-zstandard.mdx | 39 ++++++++----------- .../examples/gzip-for-csv.mdx | 37 ++++++++---------- .../examples/only-brotli-url-path.mdx | 36 ++++++++--------- 5 files changed, 82 insertions(+), 103 deletions(-) diff --git a/src/content/docs/rules/compression-rules/examples/disable-all-brotli.mdx b/src/content/docs/rules/compression-rules/examples/disable-all-brotli.mdx index d14535df6e234f9..84e49bef9212fab 100644 --- a/src/content/docs/rules/compression-rules/examples/disable-all-brotli.mdx +++ b/src/content/docs/rules/compression-rules/examples/disable-all-brotli.mdx @@ -9,7 +9,7 @@ description: Create a compression rule to turn off Brotli compression for all incoming requests of a given zone. --- -import { Example, TabItem, Tabs } from "~/components"; +import { Example, TabItem, Tabs, APIRequest } from "~/components"; @@ -34,24 +34,20 @@ If the client does not support Gzip compression, the response will be uncompress The following example sets the rules of an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation: -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "true", - "action": "compress_response", - "action_parameters": { - "algorithms": [ - { "name": "gzip" } - ] - } - } - ] -}' -``` + diff --git a/src/content/docs/rules/compression-rules/examples/disable-compression-avif.mdx b/src/content/docs/rules/compression-rules/examples/disable-compression-avif.mdx index 8137005151410d4..58b02d20ee347bf 100644 --- a/src/content/docs/rules/compression-rules/examples/disable-compression-avif.mdx +++ b/src/content/docs/rules/compression-rules/examples/disable-compression-avif.mdx @@ -11,7 +11,7 @@ description: Create a compression rule to turn off compression for AVIF images, request. --- -import { Example, TabItem, Tabs } from "~/components"; +import { Example, TabItem, Tabs, APIRequest } from "~/components"; @@ -36,24 +36,21 @@ The following example rule will disable compression for AVIF images, based on ei The following example sets the rules of an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation: -```bash wrap -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "http.response.content_type.media_type eq \"image/avif\" or http.request.uri.path.extension eq \"avif\"", - "action": "compress_response", - "action_parameters": { - "algorithms": [ - { "name": "none" } - ] - } - } - ] -}' -``` + diff --git a/src/content/docs/rules/compression-rules/examples/enable-zstandard.mdx b/src/content/docs/rules/compression-rules/examples/enable-zstandard.mdx index e9bdc75d1ab3edd..9ac33b53d5252f1 100644 --- a/src/content/docs/rules/compression-rules/examples/enable-zstandard.mdx +++ b/src/content/docs/rules/compression-rules/examples/enable-zstandard.mdx @@ -7,7 +7,7 @@ title: Enable Zstandard compression for default content types description: Create a compression rule to turn on Zstandard compression for response content types where Cloudflare applies compression by default. --- -import { Example, TabItem, Tabs } from "~/components"; +import { Example, TabItem, Tabs, APIRequest } from "~/components"; @@ -32,26 +32,21 @@ The following example rule will turn on Zstandard compression for response conte The following example sets the rules of an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation: -```bash wrap -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "(http.response.content_type.media_type in {\"text/html\" \"text/richtext\" \"text/plain\" \"text/css\" \"text/x-script\" \"text/x-component\" \"text/x-java-source\" \"text/x-markdown\" \"application/javascript\" \"application/x-javascript\" \"text/javascript\" \"text/js\" \"image/x-icon\" \"image/vnd.microsoft.icon\" \"application/x-perl\" \"application/x-httpd-cgi\" \"text/xml\" \"application/xml\" \"application/rss+xml\" \"application/vnd.api+json\" \"application/x-protobuf\" \"application/json\" \"multipart/bag\" \"multipart/mixed\" \"application/xhtml+xml\" \"font/ttf\" \"font/otf\" \"font/x-woff\" \"image/svg+xml\" \"application/vnd.ms-fontobject\" \"application/ttf\" \"application/x-ttf\" \"application/otf\" \"application/x-otf\" \"application/truetype\" \"application/opentype\" \"application/x-opentype\" \"application/font-woff\" \"application/eot\" \"application/font\" \"application/font-sfnt\" \"application/wasm\" \"application/javascript-binast\" \"application/manifest+json\" \"application/ld+json\" \"application/graphql+json\" \"application/geo+json\"})", - "action": "compress_response", - "action_parameters": { - "algorithms": [ - { "name": "zstd" }, - { "name": "brotli" }, - { "name": "gzip" } - ] - } - } - ] -}' -``` + diff --git a/src/content/docs/rules/compression-rules/examples/gzip-for-csv.mdx b/src/content/docs/rules/compression-rules/examples/gzip-for-csv.mdx index bcc73dbbb1527b2..cc95a354f981571 100644 --- a/src/content/docs/rules/compression-rules/examples/gzip-for-csv.mdx +++ b/src/content/docs/rules/compression-rules/examples/gzip-for-csv.mdx @@ -9,7 +9,7 @@ description: Create a compression rule to set Gzip compression as the preferred compression method for CSV files. --- -import { Example, TabItem, Tabs } from "~/components"; +import { Example, TabItem, Tabs, APIRequest } from "~/components"; @@ -34,25 +34,20 @@ The following example rule will configure Gzip compression as the preferred comp The following example sets the rules of an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation: -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "http.request.uri.path.extension eq \"csv\"", - "action": "compress_response", - "action_parameters": { - "algorithms": [ - { "name": "gzip" }, - { "name": "auto" } - ] - } - } - ] -}' -``` + diff --git a/src/content/docs/rules/compression-rules/examples/only-brotli-url-path.mdx b/src/content/docs/rules/compression-rules/examples/only-brotli-url-path.mdx index d4b428fba26b462..2eccbfb11d680fc 100644 --- a/src/content/docs/rules/compression-rules/examples/only-brotli-url-path.mdx +++ b/src/content/docs/rules/compression-rules/examples/only-brotli-url-path.mdx @@ -9,7 +9,7 @@ description: Create a compression rule to set Brotli as the only supported compression algorithm for a specific URI path. --- -import { Example, TabItem, Tabs } from "~/components"; +import { Example, TabItem, Tabs, APIRequest } from "~/components"; @@ -36,24 +36,20 @@ Since the rule configuration does not include _Auto_ at the end of the custom al The following example sets the rules of an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation: -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "http.request.uri.path eq \"/download/assets.tar\"", - "action": "compress_response", - "action_parameters": { - "algorithms": [ - { "name": "brotli" } - ] - } - } - ] -}' -``` + From 7087e74b0c39a8a91f92e29020eb73d76775ec09 Mon Sep 17 00:00:00 2001 From: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> Date: Wed, 26 Mar 2025 17:17:44 +0000 Subject: [PATCH 2/8] Update configuration and origin rules --- .../rules/configuration-rules/create-api.mdx | 73 ++++---- .../docs/rules/origin-rules/create-api.mdx | 168 +++++++++--------- 2 files changed, 115 insertions(+), 126 deletions(-) diff --git a/src/content/docs/rules/configuration-rules/create-api.mdx b/src/content/docs/rules/configuration-rules/create-api.mdx index 011e62613fe17ba..02111990288efc1 100644 --- a/src/content/docs/rules/configuration-rules/create-api.mdx +++ b/src/content/docs/rules/configuration-rules/create-api.mdx @@ -9,7 +9,7 @@ head: content: Create a configuration rule via API --- -import { Details, Render } from "~/components"; +import { Details, Render, APIRequest } from "~/components"; Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create configuration rules via API. @@ -39,25 +39,24 @@ Make sure your API token has the [required permissions](#required-api-token-perm The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single configuration rule — enabling Email Obfuscation and Browser Integrity Check for the contacts page — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation: -```bash title="Request" -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "starts_with(http.request.uri.path, \"/contact-us/\")", - "description": "Obfuscates email addresses and enables BIC in contacts page", - "action": "set_config", - "action_parameters": { - "email_obfuscation": true, - "bic": true - } - } - ] -}' -``` + @@ -65,24 +64,22 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single configuration rule — turning on Under Attack mode for the administration area — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation: -```bash title="Request" -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "http.host eq \"admin.example.com\"", - "description": "Turn on I'\''m Under Attack mode for admin area", - "action": "set_config", - "action_parameters": { - "security_level": "under_attack" - } - } - ] -}' -``` + diff --git a/src/content/docs/rules/origin-rules/create-api.mdx b/src/content/docs/rules/origin-rules/create-api.mdx index 53eeffee1dc5783..d9dcbe80d5868d9 100644 --- a/src/content/docs/rules/origin-rules/create-api.mdx +++ b/src/content/docs/rules/origin-rules/create-api.mdx @@ -8,7 +8,7 @@ head: content: Create an origin rule via API --- -import { Details, Render } from "~/components"; +import { Details, Render, APIRequest } from "~/components"; Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create origin rules via API. @@ -33,26 +33,24 @@ Make sure your API token has the [required permissions](#required-api-token-perm
-The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the HTTP `Host` header — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "http.request.uri.query contains \"/eu/\"", - "description": "My first origin rule", - "action": "route", - "action_parameters": { - "host_header": "eu_server.example.net" - } - } - ] -}' -``` +The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single origin rule — overriding the HTTP `Host` header — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. + + ```json output { @@ -89,56 +87,52 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
-The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the SNI value of incoming requests addressed at `admin.example.com` — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "http.host eq \"admin.example.com\"", - "description": "SNI Override for the admin area", - "action": "route", - "action_parameters": { - "sni": { - "value": "sni.example.com" - } - } - } - ] -}' -``` +The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single origin rule — overriding the SNI value of incoming requests addressed at `admin.example.com` — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. + +
-The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the resolved DNS record and the `Host` header of incoming requests — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "starts_with(http.request.uri.path, \"/hr-app/\")", - "description": "Origin rule for the company HR application", - "action": "route", - "action_parameters": { - "host_header": "hr-server.example.com", - "origin": { - "host": "hr-server.example.com" - } - } - } - ] -}' -``` +The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single origin rule — overriding the resolved DNS record and the `Host` header of incoming requests — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. + + ```json output { @@ -178,28 +172,26 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
-The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the port of incoming requests — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "starts_with(http.request.uri.path, \"/team/calendar/\")", - "description": "Origin rule for the team calendar application", - "action": "route", - "action_parameters": { - "origin": { - "port": 9000 - } - } - } - ] -}' -``` +The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single origin rule — overriding the port of incoming requests — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. + + ```json output { From 1217b075b0c404788eb563b6c85934d01b9c4b30 Mon Sep 17 00:00:00 2001 From: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> Date: Wed, 26 Mar 2025 17:18:33 +0000 Subject: [PATCH 3/8] Update custom errors examples --- .../docs/rules/custom-errors/create-api.mdx | 168 +++++++++--------- 1 file changed, 88 insertions(+), 80 deletions(-) diff --git a/src/content/docs/rules/custom-errors/create-api.mdx b/src/content/docs/rules/custom-errors/create-api.mdx index e7a6b8b5f2ea82b..1062cbbaeef98e6 100644 --- a/src/content/docs/rules/custom-errors/create-api.mdx +++ b/src/content/docs/rules/custom-errors/create-api.mdx @@ -9,6 +9,8 @@ head: content: Create custom errors via API --- +import { APIRequest } from "~/components"; + To configure custom errors via API: 1. (Optional) [Create a custom error asset](#create-a-custom-error-asset) based on a URL you provide. @@ -208,28 +210,29 @@ To create a custom error rule at the account level, use the corresponding accoun ### Custom JSON response for all 5XX errors -This example configures a custom JSON error response for all 5XX errors (`500`-`599`) in the zone with ID `{zone_id}`. The HTTP status code of the custom error response will be set to `530`. - -```bash -curl --request PUT \ -"https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_custom_errors/entrypoint" \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "action": "serve_error", - "action_parameters": { - "content": "{\"message\": \"A server error occurred.\"}", - "content_type": "application/json", - "status_code": 530 - }, - "expression": "http.response.code ge 500 and http.response.code lt 600", - "enabled": true - } - ] -}' -``` +This example configures a custom JSON error response for all 5XX errors (`500`-`599`) in the zone with ID `$ZONE_ID`. The HTTP status code of the custom error response will be set to `530`. + + This `PUT` request, corresponding to the [Update a zone entry point ruleset](/api/resources/rulesets/subresources/phases/methods/update/) operation, replaces any existing rules in the `http_custom_errors` phase entry point ruleset. @@ -237,26 +240,28 @@ This `PUT` request, corresponding to the [Update a zone entry point ruleset](/ap This example configures a custom HTML error response for responses with a `500` HTTP status code, and redefines the response status code to `503`. -```bash -curl --request PUT \ -"https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_custom_errors/entrypoint" \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "action": "serve_error", - "action_parameters": { - "content": "Application unavailable

Application temporarily unavailable

Please try again later.

", - "content_type": "text/html", - "status_code": 503 - }, - "expression": "http.response.code eq 500", - "enabled": true - } - ] -}' -``` +Application unavailable

Application temporarily unavailable

Please try again later.

', + content_type: "text/html", + status_code: 503, + }, + expression: "http.response.code eq 500", + enabled: true, + }, + ], + }} +/> This `PUT` request, corresponding to the [Update a zone entry point ruleset](/api/resources/rulesets/subresources/phases/methods/update/) operation, replaces any existing rules in the `http_custom_errors` phase entry point ruleset. @@ -264,25 +269,27 @@ This `PUT` request, corresponding to the [Update a zone entry point ruleset](/ap This example configures a custom HTML error response for [Cloudflare error 1020](/support/troubleshooting/cloudflare-errors/troubleshooting-cloudflare-1xxx-errors/#error-1020-access-denied) (Access Denied). -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_custom_errors/entrypoint \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "action": "serve_error", - "action_parameters": { - "content": "Access denied

You do not have access to this page

Contact us if you think this is an error.

", - "content_type": "text/html" - }, - "expression": "cf.response.1xxx_code eq 1020", - "enabled": true - } - ] -}' -``` +Access denied

You do not have access to this page

Contact us if you think this is an error.

', + content_type: "text/html", + }, + expression: "cf.response.1xxx_code eq 1020", + enabled: true, + }, + ], + }} +/> This `PUT` request, corresponding to the [Update a zone entry point ruleset](/api/resources/rulesets/subresources/phases/methods/update/) operation, replaces any existing rules in the `http_custom_errors` phase entry point ruleset. @@ -290,25 +297,26 @@ This `PUT` request, corresponding to the [Update a zone entry point ruleset](/ap This example configures a custom error rule returning a [previously created custom error asset](#create-a-custom-error-asset) named `500_error_template` for responses with a `500` HTTP status code. -```bash -curl --request PUT \ -"https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_custom_errors/entrypoint" \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "action": "serve_error", - "action_parameters": { - "asset_name": "500_error_template", - "content_type": "text/html" - }, - "expression": "http.response.code eq 500", - "enabled": true - } - ] -}' -``` + This `PUT` request, corresponding to the [Update a zone entry point ruleset](/api/resources/rulesets/subresources/phases/methods/update/) operation, replaces any existing rules in the `http_custom_errors` phase entry point ruleset. From 4f66077d36718c8e779b14c142995d59346c579a Mon Sep 17 00:00:00 2001 From: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> Date: Wed, 26 Mar 2025 17:19:12 +0000 Subject: [PATCH 4/8] Update Transform Rules --- .../managed-transforms/configure.mdx | 132 ++++++------ .../create-api.mdx | 144 +++++++------ .../create-api.mdx | 192 +++++++++--------- .../transform/url-rewrite/create-api.mdx | 94 ++++----- 4 files changed, 273 insertions(+), 289 deletions(-) diff --git a/src/content/docs/rules/transform/managed-transforms/configure.mdx b/src/content/docs/rules/transform/managed-transforms/configure.mdx index c4be6f3e786903b..c022ae8b9f04f33 100644 --- a/src/content/docs/rules/transform/managed-transforms/configure.mdx +++ b/src/content/docs/rules/transform/managed-transforms/configure.mdx @@ -6,7 +6,7 @@ sidebar: description: Learn how to configure Managed Transforms. --- -import { Details, TabItem, Tabs, Render } from "~/components"; +import { Details, TabItem, Tabs, Render, APIRequest } from "~/components"; @@ -28,60 +28,60 @@ Each Managed Transform item will optionally contain a `conflicts_with` array inf The response will only include available Managed Transforms according to your Cloudflare plan and product subscriptions. -```bash title="Request" -curl https://api.cloudflare.com/client/v4/zones/{zone_id}/managed_headers \ ---header "Authorization: Bearer " -``` - -
+ -```json +```json output collapse={9-40,48-52} { "result": { "managed_request_headers": [ { - "id": "add_bot_protection_headers", "enabled": false, - "has_conflict": false + "has_conflict": false, + "id": "add_bot_protection_headers" }, { - "id": "add_client_certificate_headers", "enabled": false, - "has_conflict": false + "has_conflict": false, + "id": "add_client_certificate_headers" }, { - "id": "add_visitor_location_headers", "enabled": false, - "has_conflict": false + "has_conflict": false, + "id": "add_visitor_location_headers" + }, + { + "conflicts_with": ["remove_visitor_ip_headers"], + "enabled": false, + "has_conflict": false, + "id": "add_true_client_ip_headers" }, { - "id": "add_true_client_ip_headers", + "conflicts_with": ["add_true_client_ip_headers"], "enabled": false, "has_conflict": false, - "conflicts_with": ["remove_visitor_ip_headers"] + "id": "remove_visitor_ip_headers" }, { - "id": "remove_visitor_ip_headers", "enabled": false, "has_conflict": false, - "conflicts_with": ["add_true_client_ip_headers"] + "id": "add_waf_credential_check_status_header" }, { - "id": "add_waf_credential_check_status_header", "enabled": false, - "has_conflict": false + "has_conflict": false, + "id": "add_waf_content_scan_status_header" } ], "managed_response_headers": [ { - "id": "remove_x-powered-by_header", "enabled": false, - "has_conflict": false + "has_conflict": false, + "id": "remove_x-powered-by_header" }, { - "id": "add_security_headers", "enabled": false, - "has_conflict": false + "has_conflict": false, + "id": "add_security_headers" } ] }, @@ -91,8 +91,6 @@ curl https://api.cloudflare.com/client/v4/zones/{zone_id}/managed_headers \ } ``` -
- **2. Change the status of Managed Transforms** Change the status of the [desired Managed Transforms](/rules/transform/managed-transforms/reference/) using the [Update status of Managed Transforms](/api/resources/managed_transforms/methods/edit/) operation. @@ -101,73 +99,79 @@ Add the Managed Transforms you wish to change to the request body, and update th Make sure you include the Managed Transforms you are updating in the correct JSON object (`managed_request_headers` or `managed_response_headers`). -```bash title="Request" -curl --request PATCH \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/managed_headers \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "managed_request_headers": [ - { - "id": "add_visitor_location_headers", - "enabled": true - } - ], - "managed_response_headers": [ - { - "id": "remove_x-powered-by_header", - "enabled": true - } - ] -}' -``` - The response will include all the available Managed Transforms and their new status after the update. -
+ -```json +```json output collapse={4-13,19-40,48-52} { "result": { "managed_request_headers": [ { - "id": "add_bot_protection_headers", "enabled": false, - "has_conflict": false + "has_conflict": false, + "id": "add_bot_protection_headers" }, { - "id": "add_client_certificate_headers", "enabled": false, - "has_conflict": false + "has_conflict": false, + "id": "add_client_certificate_headers" }, { - "id": "add_visitor_location_headers", "enabled": true, - "has_conflict": false + "has_conflict": false, + "id": "add_visitor_location_headers" }, { - "id": "add_true_client_ip_headers", + "conflicts_with": ["remove_visitor_ip_headers"], "enabled": false, "has_conflict": false, - "conflicts_with": ["remove_visitor_ip_headers"] + "id": "add_true_client_ip_headers" }, { - "id": "remove_visitor_ip_headers", + "conflicts_with": ["add_true_client_ip_headers"], "enabled": false, "has_conflict": false, - "conflicts_with": ["add_true_client_ip_headers"] + "id": "remove_visitor_ip_headers" + }, + { + "enabled": false, + "has_conflict": false, + "id": "add_waf_credential_check_status_header" + }, + { + "enabled": false, + "has_conflict": false, + "id": "add_waf_content_scan_status_header" } ], "managed_response_headers": [ { - "id": "remove_x-powered-by_header", "enabled": true, - "has_conflict": false + "has_conflict": false, + "id": "remove_x-powered-by_header" }, { - "id": "add_security_headers", "enabled": false, - "has_conflict": false + "has_conflict": false, + "id": "add_security_headers" } ] }, @@ -177,8 +181,6 @@ The response will include all the available Managed Transforms and their new sta } ``` -
-
diff --git a/src/content/docs/rules/transform/request-header-modification/create-api.mdx b/src/content/docs/rules/transform/request-header-modification/create-api.mdx index 3e104deae55d454..26ffd5ee76796e0 100644 --- a/src/content/docs/rules/transform/request-header-modification/create-api.mdx +++ b/src/content/docs/rules/transform/request-header-modification/create-api.mdx @@ -9,7 +9,7 @@ head: content: Create an HTTP request header modification rule via API --- -import { Details, Render } from "~/components"; +import { Details, Render, APIRequest } from "~/components"; Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create HTTP request header modification rules via API. Refer to the [Rules examples gallery](/rules/transform/examples/?operation=Request+modification) for common use cases. @@ -37,31 +37,29 @@ Make sure your API token has the [required permissions](#required-api-token-perm
-The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single HTTP request header modification rule — adding an HTTP request header with a static value — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP request header modification rule", - "action": "rewrite", - "action_parameters": { - "headers": { - "X-Source": { - "operation": "set", - "value": "Cloudflare" - } - } - } - } - ] -}' -``` +The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single HTTP request header modification rule — adding an HTTP request header with a static value — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. + + ```json output { @@ -103,31 +101,29 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
-The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single HTTP request header modification rule — adding an HTTP request header with a dynamic value — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP request header modification rule", - "action": "rewrite", - "action_parameters": { - "headers": { - "X-Bot-Score": { - "operation": "set", - "expression": "to_string(cf.bot_management.score)" - } - } - } - } - ] -}' -``` +The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single HTTP request header modification rule — adding an HTTP request header with a dynamic value — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. + + ```json output { @@ -169,30 +165,28 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
-The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single HTTP request header modification rule — removing an HTTP request header — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/). The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP request header modification rule", - "action": "rewrite", - "action_parameters": { - "headers": { - "cf-connecting-ip": { - "operation": "remove" - } - } - } - } - ] -}' -``` +The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single HTTP request header modification rule — removing an HTTP request header — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/). The response will contain the complete definition of the ruleset you updated. + + ```json output { diff --git a/src/content/docs/rules/transform/response-header-modification/create-api.mdx b/src/content/docs/rules/transform/response-header-modification/create-api.mdx index f9345306b3c5540..bedb2915a9a143f 100644 --- a/src/content/docs/rules/transform/response-header-modification/create-api.mdx +++ b/src/content/docs/rules/transform/response-header-modification/create-api.mdx @@ -8,7 +8,7 @@ head: content: Create an HTTP response header modification rule via API --- -import { Details, Render } from "~/components"; +import { Details, Render, APIRequest } from "~/components"; Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create HTTP response header modification rules via API. Refer to the [Rules examples gallery](/rules/transform/examples/?operation=Response+modification) for common use cases. @@ -36,31 +36,29 @@ Make sure your API token has the [required permissions](#required-api-token-perm
-The following example configures the rules of an existing phase ruleset (`{ruleset_id}`) to a single HTTP response header modification rule — setting an HTTP response header to a static value — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP response header modification rule", - "action": "rewrite", - "action_parameters": { - "headers": { - "X-Source": { - "operation": "set", - "value": "Cloudflare" - } - } - } - } - ] -}' -``` +The following example configures the rules of an existing phase ruleset (`$RULESET_ID`) to a single HTTP response header modification rule — setting an HTTP response header to a static value — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. + + ```json output { @@ -102,31 +100,29 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
-The following example configures the rules of an existing phase ruleset (`{ruleset_id}`) to a single HTTP response header modification rule — setting an HTTP response header to a dynamic value — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP response header modification rule", - "action": "rewrite", - "action_parameters": { - "headers": { - "X-Bot-Score": { - "operation": "set", - "expression": "to_string(cf.bot_management.score)" - } - } - } - } - ] -}' -``` +The following example configures the rules of an existing phase ruleset (`$RULESET_ID`) to a single HTTP response header modification rule — setting an HTTP response header to a dynamic value — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. + + ```json output { @@ -168,31 +164,29 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
-The following example configures the rules of an existing phase ruleset (`{ruleset_id}`) to a single HTTP response header modification rule — adding a `set-cookie` HTTP response header with a static value — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. By configuring the rule with the `add` operation you will keep any existing `set-cookie` headers that may already exist in the response. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP response header modification rule", - "action": "rewrite", - "action_parameters": { - "headers": { - "set-cookie": { - "operation": "add", - "value": "mycookie=custom_value" - } - } - } - } - ] -}' -``` +The following example configures the rules of an existing phase ruleset (`$RULESET_ID`) to a single HTTP response header modification rule — adding a `set-cookie` HTTP response header with a static value — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. By configuring the rule with the `add` operation you will keep any existing `set-cookie` headers that may already exist in the response. The response will contain the complete definition of the ruleset you updated. + + ```json output { @@ -234,30 +228,28 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
-The following example sets the rules of an existing phase ruleset (``) to a single HTTP response header modification rule — removing an HTTP response header — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP response header modification rule", - "action": "rewrite", - "action_parameters": { - "headers": { - "cf-connecting-ip": { - "operation": "remove" - } - } - } - } - ] -}' -``` +The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single HTTP response header modification rule — removing an HTTP response header — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. + + ```json output { diff --git a/src/content/docs/rules/transform/url-rewrite/create-api.mdx b/src/content/docs/rules/transform/url-rewrite/create-api.mdx index be7427973b9b72f..7e1e7be68e7fd6d 100644 --- a/src/content/docs/rules/transform/url-rewrite/create-api.mdx +++ b/src/content/docs/rules/transform/url-rewrite/create-api.mdx @@ -8,7 +8,7 @@ head: content: Create a rewrite URL rule via API --- -import { Details, Render } from "~/components"; +import { Details, Render, APIRequest } from "~/components"; Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create rewrite URL rules via API. Refer to the [Rules examples gallery](/rules/transform/examples/?operation=Rewrite+URL) for common use cases. @@ -36,30 +36,28 @@ Make sure your API token has the [required permissions](#required-api-token-perm
-The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single rewrite URL rule — performing a static rewrite of the URI path — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "(http.request.uri.query contains \"eu\")", - "description": "My first static rewrite URL rule", - "action": "rewrite", - "action_parameters": { - "uri": { - "path": { - "value": "/emea.html" - } - } - } - } - ] -}' -``` +The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single rewrite URL rule — performing a static rewrite of the URI path — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. + + ```json output { @@ -100,30 +98,28 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
-The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single rewrite URL rule — performing a dynamic rewrite of the URI path — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. - -```bash -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "expression": "starts_with(http.request.uri.path, \"/news/2012/\")", - "description": "My first dynamic rewrite URL rule", - "action": "rewrite", - "action_parameters": { - "uri": { - "path": { - "expression": "concat(\"/archive\", http.request.uri.path)" - } - } - } - } - ] -}' -``` +The following example sets the rules of an existing phase ruleset (`$RULESET_ID`) to a single rewrite URL rule — performing a dynamic rewrite of the URI path — using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation. The response will contain the complete definition of the ruleset you updated. + + ```json output { From cd90c69770f309a40003c16845e681861dfa16e3 Mon Sep 17 00:00:00 2001 From: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> Date: Wed, 26 Mar 2025 17:26:40 +0000 Subject: [PATCH 5/8] Update examples that require a component fix (TODO) --- .../docs/rules/cloud-connector/create-api.mdx | 22 +++++++-- .../docs/rules/snippets/create-api.mdx | 45 ++++++++++++------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/content/docs/rules/cloud-connector/create-api.mdx b/src/content/docs/rules/cloud-connector/create-api.mdx index 858cf560d4e6905..e149a062f614169 100644 --- a/src/content/docs/rules/cloud-connector/create-api.mdx +++ b/src/content/docs/rules/cloud-connector/create-api.mdx @@ -8,6 +8,8 @@ head: content: Configure a Cloud Connector rule via API --- +import { APIRequest } from "~/components"; + You can configure Cloud Connector rules using the [Cloudflare API](/fundamentals/api/). ## Required permissions @@ -43,10 +45,7 @@ The following table summarizes the available operations. The following example returns a list of existing Cloud Connector rules: -```bash -curl https://api.cloudflare.com/client/v4/zones/{zone_id}/cloud_connector/rules \ ---header "Authorization: Bearer " -``` + ```json output { @@ -76,6 +75,21 @@ To create a new rule and keep all existing rules, you must include them all in y The following example request will replace all existing Cloud Connector rules with a single rule: +TODO Fix example. + + + ```bash curl --request PUT \ "https://api.cloudflare.com/client/v4/zones/{zone_id}/cloud_connector/rules" \ diff --git a/src/content/docs/rules/snippets/create-api.mdx b/src/content/docs/rules/snippets/create-api.mdx index e0a823242d01409..687e893c5408b2d 100644 --- a/src/content/docs/rules/snippets/create-api.mdx +++ b/src/content/docs/rules/snippets/create-api.mdx @@ -9,6 +9,8 @@ head: content: Configure Snippets via API --- +import { APIRequest } from "~/components"; + You can create Snippets using the [Cloudflare API](/fundamentals/api/). ## Required permissions @@ -48,7 +50,18 @@ The following table summarizes the available operations. ### Create/update code snippet -To create or update a Snippet, use the following `PUT` request. The snippet is named `{snippet_name}` and the body contains the JavaScript code. +To create or update a Snippet, use the following `PUT` request. The snippet is named `$SNIPPET_NAME` and the body contains the JavaScript code. + +TODO Fix example. + + ```bash curl --request PUT https://api.cloudflare.com/client/v4/zones/{zone_id}/snippets/{snippet_name} \ @@ -90,19 +103,17 @@ When using this endpoint to create a new rule and keep existing rules, you must Once you have created a code snippet, you can link it to rules. This is done via the following `PUT` request to the `snippet_rules` endpoint. -```bash -curl --request PUT \ -"https://api.cloudflare.com/client/v4/zones/{zone_id}/snippets/snippet_rules" \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "rules": [ - { - "description": "Trigger snippet on specific cookie", - "enabled": true, - "expression": "http.cookie eq \"a=b\"", - "snippet_name": "snippet_name_01" - } - ] -}' -``` + From fcbb2a1de19f08a8a7e3f23cf6c162b85d4c9e09 Mon Sep 17 00:00:00 2001 From: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> Date: Wed, 26 Mar 2025 17:41:17 +0000 Subject: [PATCH 6/8] Add bulk redirects examples (TODO) --- .../bulk-redirects/create-api.mdx | 172 ++++++++++-------- 1 file changed, 99 insertions(+), 73 deletions(-) diff --git a/src/content/docs/rules/url-forwarding/bulk-redirects/create-api.mdx b/src/content/docs/rules/url-forwarding/bulk-redirects/create-api.mdx index 428ae57009f25f4..fe782a157a34bdd 100644 --- a/src/content/docs/rules/url-forwarding/bulk-redirects/create-api.mdx +++ b/src/content/docs/rules/url-forwarding/bulk-redirects/create-api.mdx @@ -7,7 +7,7 @@ sidebar: description: Learn how to create Bulk Redirects using the Cloudflare API. --- -import { Render } from "~/components"; +import { Render, APIRequest } from "~/components"; To create Bulk Redirects via API, you must: @@ -24,16 +24,15 @@ To create Bulk Redirects via API, you must: Use the [Create a list](/api/resources/rules/subresources/lists/methods/create/) operation to create a new Bulk Redirect List. The list `kind` must be `redirect`. -```bash -curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "name": "my_redirect_list", - "description": "My redirect list.", - "kind": "redirect" -}' -``` + ```json output {3} { @@ -61,6 +60,33 @@ For more information on list operations, refer to the [Lists API](/waf/tools/lis Use the [Create list items](/api/resources/rules/subresources/lists/subresources/items/methods/create/) operation to add URL redirect items to the list. Enter the list ID from the previous step in the endpoint URL: +TODO Fix example. + + + ```bash curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists/f848b6ccb07647749411f504d6f88794/items \ --header "Authorization: Bearer " \ @@ -95,10 +121,13 @@ curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists/f848 This is an asynchronous operation. The response will contain an `operation_id` which you will use to check if the operation completed successfully using the [Get bulk operation status](/api/resources/rules/subresources/lists/subresources/bulk_operations/methods/get/) operation: -```bash -curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists/bulk_operations/92558f8b296d4dbe9d0419e0e53f6622 \ ---header "Authorization: Bearer " -``` + Once the operation has completed successfully, the response will be similar to the following: @@ -128,29 +157,28 @@ A Bulk Redirect Rule must have: The following request of the [Create an account ruleset](/api/resources/rulesets/methods/create/) operation creates a phase entry point ruleset for the `http_request_redirect` phase at the account level, and defines a single redirect rule. Use this operation if you have not created a phase entry point ruleset for the `http_request_redirect` phase yet. -```bash -curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "name": "My redirect ruleset", - "kind": "root", - "phase": "http_request_redirect", - "rules": [ - { - "expression": "http.request.full_uri in $my_redirect_list", - "description": "Bulk Redirect rule.", - "action": "redirect", - "action_parameters": { - "from_list": { - "name": "my_redirect_list", - "key": "http.request.full_uri" - } - } - } - ] -}' -``` + ```json output { @@ -186,41 +214,39 @@ curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets \ If there is already a phase entry point ruleset for the `http_request_redirect` phase, use the [Update an account ruleset](/api/resources/rulesets/methods/update/) operation instead, like in the following example: -```bash -curl --request PUT \ -"https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{ruleset_id}" \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "name": "My redirect ruleset", - "kind": "root", - "phase": "http_request_redirect", - "rules": [ - { - "expression": "http.request.full_uri in $my_redirect_list_2", - "description": "Bulk Redirect rule 1", - "action": "redirect", - "action_parameters": { - "from_list": { - "name": "my_redirect_list_1", - "key": "http.request.full_uri" - } - } - }, - { - "expression": "http.request.full_uri in $my_redirect_list_2", - "description": "Bulk Redirect rule 2", - "action": "redirect", - "action_parameters": { - "from_list": { - "name": "my_redirect_list_2", - "key": "http.request.full_uri" - } - } - } - ] -}' -``` + ```json output { From af0157c623bb51dc853614d6e59191450310c501 Mon Sep 17 00:00:00 2001 From: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> Date: Wed, 26 Mar 2025 17:46:40 +0000 Subject: [PATCH 7/8] Update single redirects examples --- .../single-redirects/create-api.mdx | 135 +++++++++--------- 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/src/content/docs/rules/url-forwarding/single-redirects/create-api.mdx b/src/content/docs/rules/url-forwarding/single-redirects/create-api.mdx index 1c5fce2d3e15c79..9df7fa7e0731b5b 100644 --- a/src/content/docs/rules/url-forwarding/single-redirects/create-api.mdx +++ b/src/content/docs/rules/url-forwarding/single-redirects/create-api.mdx @@ -6,7 +6,7 @@ sidebar: label: Create rule via API --- -import { Details, Render } from "~/components"; +import { Details, Render, APIRequest } from "~/components"; Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create a redirect rule via API. @@ -28,32 +28,33 @@ A redirect rule must have: The following request of the [Create a zone ruleset](/api/resources/rulesets/methods/create/) operation creates a phase entry point ruleset for the `http_request_dynamic_redirect` phase at the zone level, and defines a single redirect rule with a dynamic URL redirect. Use this operation if you have not created a phase entry point ruleset for the `http_request_dynamic_redirect` phase yet. -```bash title="Request" -curl https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "name": "Redirect rules ruleset", - "kind": "zone", - "phase": "http_request_dynamic_redirect", - "rules": [ - { - "expression": "(ip.src.country eq \"GB\" or ip.src.country eq \"FR\") and http.request.uri.path eq \"/\"", - "description": "Redirect GB and FR users in home page to localized site.", - "action": "redirect", - "action_parameters": { - "from_value": { - "target_url": { - "expression": "lower(concat(\"https://\", ip.src.country, \".example.com\"))" - }, - "status_code": 307, - "preserve_query_string": true - } - } - } - ] -}' -``` +
@@ -96,46 +97,46 @@ curl https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets \ If there is already a phase entry point ruleset for the `http_request_dynamic_redirect` phase, use the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation instead, like in the following example: -```bash title="Request" -curl --request PUT \ -https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '{ - "name": "Redirect rules ruleset", - "kind": "zone", - "phase": "http_request_dynamic_redirect", - "rules": [ - { - "expression": "(ip.src.country eq \"GB\" or ip.src.country eq \"FR\") and http.request.uri.path eq \"/\"", - "description": "Redirect GB and FR users in home page to localized site.", - "action": "redirect", - "action_parameters": { - "from_value": { - "target_url": { - "expression": "lower(concat(\"https://\", ip.src.country, \".example.com\"))" - }, - "status_code": 307, - "preserve_query_string": true - } - } - }, - { - "expression": "http.request.uri.path eq \"/contacts.html\"", - "description": "Redirect to new contacts page.", - "action": "redirect", - "action_parameters": { - "from_value": { - "target_url": { - "value": "https://example.com/contact-us/" - }, - "status_code": 308 - } - } - } - ] -}' -``` +
From 2b8dc09bb17670760c8e5788930708bdcee52528 Mon Sep 17 00:00:00 2001 From: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> Date: Wed, 2 Apr 2025 10:11:31 +0100 Subject: [PATCH 8/8] Fix examples after component update --- .../docs/rules/cloud-connector/create-api.mdx | 35 ++++--------- .../docs/rules/snippets/create-api.mdx | 10 ---- .../bulk-redirects/create-api.mdx | 51 +++++-------------- 3 files changed, 22 insertions(+), 74 deletions(-) diff --git a/src/content/docs/rules/cloud-connector/create-api.mdx b/src/content/docs/rules/cloud-connector/create-api.mdx index e149a062f614169..d9886078750b461 100644 --- a/src/content/docs/rules/cloud-connector/create-api.mdx +++ b/src/content/docs/rules/cloud-connector/create-api.mdx @@ -75,38 +75,21 @@ To create a new rule and keep all existing rules, you must include them all in y The following example request will replace all existing Cloud Connector rules with a single rule: -TODO Fix example. - -```bash -curl --request PUT \ -"https://api.cloudflare.com/client/v4/zones/{zone_id}/cloud_connector/rules" \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '[ - { - "expression": "http.request.uri.path wildcard \"/images/*\"", - "provider": "cloudflare_r2", - "description": "Connect to R2 bucket containing images", - "parameters": { - "host": "mybucketcustomdomain.example.com" - } - } -]' -``` - The required body parameters for each rule are: `expression`, `provider`, and `parameters.host`. The `provider` value must be one of the following: `cloudflare_r2`, `aws_s3`, `azure_storage`, and `gcp_storage`. diff --git a/src/content/docs/rules/snippets/create-api.mdx b/src/content/docs/rules/snippets/create-api.mdx index 687e893c5408b2d..5220f5bcde4af94 100644 --- a/src/content/docs/rules/snippets/create-api.mdx +++ b/src/content/docs/rules/snippets/create-api.mdx @@ -52,8 +52,6 @@ The following table summarizes the available operations. To create or update a Snippet, use the following `PUT` request. The snippet is named `$SNIPPET_NAME` and the body contains the JavaScript code. -TODO Fix example. - -```bash -curl --request PUT https://api.cloudflare.com/client/v4/zones/{zone_id}/snippets/{snippet_name} \ ---header "Authorization: Bearer " \ ---header "Content-Type: multipart/form-data" \ ---form files=@example.js \ ---form metadata='{"main_module":"example.js"}' -``` - The name of a snippet can only contain the characters `a-z`, `0-9`, and `_` (underscore). The name must be unique in the context of the zone. You cannot change the snippet name after creating the snippet. The required body parameters are: diff --git a/src/content/docs/rules/url-forwarding/bulk-redirects/create-api.mdx b/src/content/docs/rules/url-forwarding/bulk-redirects/create-api.mdx index fe782a157a34bdd..af5ce0f08dc4dd7 100644 --- a/src/content/docs/rules/url-forwarding/bulk-redirects/create-api.mdx +++ b/src/content/docs/rules/url-forwarding/bulk-redirects/create-api.mdx @@ -60,54 +60,29 @@ For more information on list operations, refer to the [Lists API](/waf/tools/lis Use the [Create list items](/api/resources/rules/subresources/lists/subresources/items/methods/create/) operation to add URL redirect items to the list. Enter the list ID from the previous step in the endpoint URL: -TODO Fix example. - -```bash -curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists/f848b6ccb07647749411f504d6f88794/items \ ---header "Authorization: Bearer " \ ---header "Content-Type: application/json" \ ---data '[ - { - "redirect": { - "source_url": "example.com/blog/", - "target_url": "https://example.com/blog/latest" - } - }, - { - "redirect": { - "source_url": "example.net/", - "target_url": "https://example.net/under-construction.html", - "status_code": 307 - } - } -]' -``` - ```json output { "result": {