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 deniedYou 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 deniedYou 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": {