diff --git a/src/content/docs/rules/cloud-connector/create-api.mdx b/src/content/docs/rules/cloud-connector/create-api.mdx index 46bb8a974fb4c82..d1378c0f4a57a89 100644 --- a/src/content/docs/rules/cloud-connector/create-api.mdx +++ b/src/content/docs/rules/cloud-connector/create-api.mdx @@ -48,7 +48,7 @@ curl https://api.cloudflare.com/client/v4/zones/{zone_id}/cloud_connector/rules --header "Authorization: Bearer " ``` -```json title="Example response" +```json output { "result": [ { diff --git a/src/content/docs/rules/origin-rules/create-api.mdx b/src/content/docs/rules/origin-rules/create-api.mdx index 59626c97b8a7ad5..3386adf6478f12b 100644 --- a/src/content/docs/rules/origin-rules/create-api.mdx +++ b/src/content/docs/rules/origin-rules/create-api.mdx @@ -6,10 +6,9 @@ sidebar: head: - tag: title content: Create an origin rule via API - --- -import { Details, Render } from "~/components" +import { Details, Render } from "~/components"; Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create origin rules via API. @@ -17,24 +16,26 @@ Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create origin rules via When creating an origin rule via API, make sure you: -* Set the rule action to `route`. -* Define the [parameters](/rules/origin-rules/parameters/) in the `action_parameters` field according to the type of origin override. -* Deploy the rule to the `http_request_origin` phase at the zone level. +- Set the rule action to `route`. +- Define the [parameters](/rules/origin-rules/parameters/) in the `action_parameters` field according to the type of origin override. +- Deploy the rule to the `http_request_origin` phase at the zone level. ## Procedure - + Make sure your API token has the [required permissions](#required-api-token-permissions) to perform the API operations. ## Example requests -
-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/operations/updateZoneRuleset) operation: +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/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -53,48 +54,44 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Origin Rules ruleset", - "description": "Zone-level ruleset that will execute origin rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "route", - "action_parameters": { - "host_header": "eu_server.example.net" - }, - "expression": "http.request.uri.query contains \"/eu/\"", - "description": "My first origin rule", - "last_updated": "2022-06-02T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2022-06-02T14:42:04.219025Z", - "phase": "http_request_origin" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Origin Rules ruleset", + "description": "Zone-level ruleset that will execute origin rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "route", + "action_parameters": { + "host_header": "eu_server.example.net" + }, + "expression": "http.request.uri.query contains \"/eu/\"", + "description": "My first origin rule", + "last_updated": "2022-06-02T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2022-06-02T14:42:04.219025Z", + "phase": "http_request_origin" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-
-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/operations/updateZoneRuleset) operation: +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/operations/updateZoneRuleset) operation. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -115,15 +112,13 @@ 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 resolved DNS record and the `Host` header of incoming requests — using the [Update a zone ruleset](/api/operations/updateZoneRuleset) 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/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -145,51 +140,47 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Origin Rules ruleset", - "description": "Zone-level ruleset that will execute origin rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "route", - "action_parameters": { - "host_header": "hr-server.example.com", - "origin": { - "host": "hr-server.example.com" - } - }, - "expression": "starts_with(http.request.uri.path, \"/hr-app/\")", - "description": "Origin rule for the company HR application", - "last_updated": "2022-06-03T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2022-06-03T14:42:04.219025Z", - "phase": "http_request_origin" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Origin Rules ruleset", + "description": "Zone-level ruleset that will execute origin rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "route", + "action_parameters": { + "host_header": "hr-server.example.com", + "origin": { + "host": "hr-server.example.com" + } + }, + "expression": "starts_with(http.request.uri.path, \"/hr-app/\")", + "description": "Origin rule for the company HR application", + "last_updated": "2022-06-03T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2022-06-03T14:42:04.219025Z", + "phase": "http_request_origin" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-
-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/operations/updateZoneRuleset) operation: +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/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -210,48 +201,45 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Origin Rules ruleset", - "description": "Zone-level ruleset that will execute origin rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "route", - "action_parameters": { - "origin": { - "port": 9000 - } - }, - "expression": "starts_with(http.request.uri.path, \"/team/calendar/\")", - "description": "Origin rule for the team calendar application", - "last_updated": "2022-06-03T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2022-06-03T14:42:04.219025Z", - "phase": "http_request_origin" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Origin Rules ruleset", + "description": "Zone-level ruleset that will execute origin rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "route", + "action_parameters": { + "origin": { + "port": 9000 + } + }, + "expression": "starts_with(http.request.uri.path, \"/team/calendar/\")", + "description": "Origin rule for the team calendar application", + "last_updated": "2022-06-03T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2022-06-03T14:42:04.219025Z", + "phase": "http_request_origin" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-*** +--- ## Required API token permissions The API token used in API requests to manage origin rules must have at least the following permission: -* *Origin* > *Edit* +- _Origin_ > _Edit_ 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 0193046035bfabe..a20cf9dc4c81a68 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 @@ -7,10 +7,9 @@ sidebar: head: - tag: title content: Create an HTTP request header modification rule via API - --- -import { Details, Render } from "~/components" +import { Details, Render } 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. @@ -18,24 +17,29 @@ Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create HTTP request hea When creating an HTTP request header modification rule via API, make sure you: -* Set the rule action to `rewrite`. -* Define the [header modification parameters](/rules/transform/request-header-modification/reference/parameters/) in the `action_parameters` field according to the operation to perform (set or remove header). -* Deploy the rule to the `http_request_late_transform` phase at the zone level. +- Set the rule action to `rewrite`. +- Define the [header modification parameters](/rules/transform/request-header-modification/reference/parameters/) in the `action_parameters` field according to the operation to perform (set or remove header). +- Deploy the rule to the `http_request_late_transform` phase at the zone level. ## Procedure - + Make sure your API token has the [required permissions](#required-api-token-permissions) to perform the API operations. ## Example requests -
-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/operations/updateZoneRuleset) operation: +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/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -59,53 +63,49 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Zone-level Late Transform Ruleset", - "description": "Zone-level ruleset that will execute Late Transform Rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "rewrite", - "action_parameters": { - "headers": { - "X-Source": { - "operation": "set", - "value": "Cloudflare" - } - } - }, - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP request header modification rule", - "last_updated": "2021-04-14T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2021-04-14T14:42:04.219025Z", - "phase": "http_request_late_transform" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Zone-level Late Transform Ruleset", + "description": "Zone-level ruleset that will execute Late Transform Rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "rewrite", + "action_parameters": { + "headers": { + "X-Source": { + "operation": "set", + "value": "Cloudflare" + } + } + }, + "expression": "(starts_with(http.request.uri.path, \"/en/\"))", + "description": "My first HTTP request header modification rule", + "last_updated": "2021-04-14T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2021-04-14T14:42:04.219025Z", + "phase": "http_request_late_transform" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-
-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/operations/updateZoneRuleset) operation: +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/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -129,53 +129,49 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Zone-level Late Transform Ruleset", - "description": "Zone-level ruleset that will execute Late Transform Rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "rewrite", - "action_parameters": { - "headers": { - "X-Bot-Score": { - "operation": "set", - "expression": "to_string(cf.bot_management.score)" - } - } - }, - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP request header modification rule", - "last_updated": "2021-04-14T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2021-04-14T14:42:04.219025Z", - "phase": "http_request_late_transform" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Zone-level Late Transform Ruleset", + "description": "Zone-level ruleset that will execute Late Transform Rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "rewrite", + "action_parameters": { + "headers": { + "X-Bot-Score": { + "operation": "set", + "expression": "to_string(cf.bot_management.score)" + } + } + }, + "expression": "(starts_with(http.request.uri.path, \"/en/\"))", + "description": "My first HTTP request header modification rule", + "last_updated": "2021-04-14T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2021-04-14T14:42:04.219025Z", + "phase": "http_request_late_transform" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-
-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/operations/updateZoneRuleset): +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/operations/updateZoneRuleset). The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -198,51 +194,48 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Zone-level Late Transform Ruleset", - "description": "Zone-level ruleset that will execute Late Transform Rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "rewrite", - "action_parameters": { - "headers": { - "cf-connecting-ip": { - "operation": "remove" - } - } - }, - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP request header modification rule", - "last_updated": "2021-04-14T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2021-04-14T14:42:04.219025Z", - "phase": "http_request_late_transform" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Zone-level Late Transform Ruleset", + "description": "Zone-level ruleset that will execute Late Transform Rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "rewrite", + "action_parameters": { + "headers": { + "cf-connecting-ip": { + "operation": "remove" + } + } + }, + "expression": "(starts_with(http.request.uri.path, \"/en/\"))", + "description": "My first HTTP request header modification rule", + "last_updated": "2021-04-14T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2021-04-14T14:42:04.219025Z", + "phase": "http_request_late_transform" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-*** +--- ## Required API token permissions The API token used in API requests to manage HTTP request header modification rules must have at least the following permissions: -* *Transform Rules* > *Edit* -* *Account Rulesets* > *Read* +- _Transform Rules_ > _Edit_ +- _Account Rulesets_ > _Read_ 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 fd845f7af6c5606..c56d3efee329f06 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 @@ -6,10 +6,9 @@ sidebar: head: - tag: title content: Create an HTTP response header modification rule via API - --- -import { Details, Render } from "~/components" +import { Details, Render } 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. @@ -17,24 +16,29 @@ Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create HTTP response he When creating an HTTP response header modification rule via API, make sure you: -* Set the rule action to `rewrite`. -* Define the [header modification parameters](/rules/transform/request-header-modification/reference/parameters/) in the `action_parameters` field according to the operation to perform (set, add, or remove header). -* Deploy the rule to the `http_response_headers_transform` phase at the zone level. +- Set the rule action to `rewrite`. +- Define the [header modification parameters](/rules/transform/request-header-modification/reference/parameters/) in the `action_parameters` field according to the operation to perform (set, add, or remove header). +- Deploy the rule to the `http_response_headers_transform` phase at the zone level. ## Procedure - + Make sure your API token has the [required permissions](#required-api-token-permissions) to perform the API operations. ## Example requests -
-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/operations/updateZoneRuleset) operation: +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/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -58,53 +62,49 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Zone-level Response Headers Transform Ruleset", - "description": "Zone-level ruleset that will execute Response Header Modification Rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "rewrite", - "action_parameters": { - "headers": { - "X-Source": { - "operation": "set", - "value": "Cloudflare" - } - } - }, - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP response header modification rule", - "last_updated": "2021-04-14T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2021-04-14T14:42:04.219025Z", - "phase": "http_response_headers_transform" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Zone-level Response Headers Transform Ruleset", + "description": "Zone-level ruleset that will execute Response Header Modification Rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "rewrite", + "action_parameters": { + "headers": { + "X-Source": { + "operation": "set", + "value": "Cloudflare" + } + } + }, + "expression": "(starts_with(http.request.uri.path, \"/en/\"))", + "description": "My first HTTP response header modification rule", + "last_updated": "2021-04-14T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2021-04-14T14:42:04.219025Z", + "phase": "http_response_headers_transform" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-
-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/operations/updateZoneRuleset) operation: +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/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -128,53 +128,49 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Zone-level Response Headers Transform Ruleset", - "description": "Zone-level ruleset that will execute Response Header Modification Rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "rewrite", - "action_parameters": { - "headers": { - "X-Bot-Score": { - "operation": "set", - "expression": "to_string(cf.bot_management.score)" - } - } - }, - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP response header modification rule", - "last_updated": "2021-04-14T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2021-04-14T14:42:04.219025Z", - "phase": "http_response_headers_transform" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Zone-level Response Headers Transform Ruleset", + "description": "Zone-level ruleset that will execute Response Header Modification Rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "rewrite", + "action_parameters": { + "headers": { + "X-Bot-Score": { + "operation": "set", + "expression": "to_string(cf.bot_management.score)" + } + } + }, + "expression": "(starts_with(http.request.uri.path, \"/en/\"))", + "description": "My first HTTP response header modification rule", + "last_updated": "2021-04-14T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2021-04-14T14:42:04.219025Z", + "phase": "http_response_headers_transform" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-
-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/operations/updateZoneRuleset) 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 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/operations/updateZoneRuleset) 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 title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -198,53 +194,49 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Zone-level Response Headers Transform Ruleset", - "description": "Zone-level ruleset that will execute Response Header Modification Rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "rewrite", - "action_parameters": { - "headers": { - "set-cookie": { - "operation": "add", - "value": "mycookie=custom_value" - } - } - }, - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP response header modification rule", - "last_updated": "2021-04-14T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2021-04-14T14:42:04.219025Z", - "phase": "http_response_headers_transform" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Zone-level Response Headers Transform Ruleset", + "description": "Zone-level ruleset that will execute Response Header Modification Rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "rewrite", + "action_parameters": { + "headers": { + "set-cookie": { + "operation": "add", + "value": "mycookie=custom_value" + } + } + }, + "expression": "(starts_with(http.request.uri.path, \"/en/\"))", + "description": "My first HTTP response header modification rule", + "last_updated": "2021-04-14T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2021-04-14T14:42:04.219025Z", + "phase": "http_response_headers_transform" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-
-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/operations/updateZoneRuleset) operation: +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/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -267,51 +259,48 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Zone-level Response Headers Transform Ruleset", - "description": "Zone-level ruleset that will execute Response Header Modification Rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "rewrite", - "action_parameters": { - "headers": { - "cf-connecting-ip": { - "operation": "remove" - } - } - }, - "expression": "(starts_with(http.request.uri.path, \"/en/\"))", - "description": "My first HTTP response header modification rule", - "last_updated": "2021-04-14T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2021-04-14T14:42:04.219025Z", - "phase": "http_response_headers_transform" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Zone-level Response Headers Transform Ruleset", + "description": "Zone-level ruleset that will execute Response Header Modification Rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "rewrite", + "action_parameters": { + "headers": { + "cf-connecting-ip": { + "operation": "remove" + } + } + }, + "expression": "(starts_with(http.request.uri.path, \"/en/\"))", + "description": "My first HTTP response header modification rule", + "last_updated": "2021-04-14T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2021-04-14T14:42:04.219025Z", + "phase": "http_response_headers_transform" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-*** +--- ## Required API token permissions The API token used in API requests to manage HTTP response header modification rules must have at least the following permissions: -* *Transform Rules* > *Edit* -* *Account Rulesets* > *Read* +- _Transform Rules_ > _Edit_ +- _Account Rulesets_ > _Read_ 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 18e76d7fe402643..d7faec50d961aed 100644 --- a/src/content/docs/rules/transform/url-rewrite/create-api.mdx +++ b/src/content/docs/rules/transform/url-rewrite/create-api.mdx @@ -6,10 +6,9 @@ sidebar: head: - tag: title content: Create a rewrite URL rule via API - --- -import { Details, Render } from "~/components" +import { Details, Render } 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. @@ -17,24 +16,26 @@ Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create rewrite URL rule When creating a rewrite URL rule via API, make sure you: -* Set the rule action to `rewrite`. -* Define the [URL rewrite parameters](/rules/transform/url-rewrite/reference/parameters/#api-information) in the `action_parameters` field according to the type of URL rewrite (static or dynamic). -* Deploy the rule to the `http_request_transform` phase at the zone level. +- Set the rule action to `rewrite`. +- Define the [URL rewrite parameters](/rules/transform/url-rewrite/reference/parameters/#api-information) in the `action_parameters` field according to the type of URL rewrite (static or dynamic). +- Deploy the rule to the `http_request_transform` phase at the zone level. ## Procedure - + Make sure your API token has the [required permissions](#required-api-token-permissions) to perform the API operations. ## Example requests -
-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/operations/updateZoneRuleset) operation: +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/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -57,52 +58,48 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Zone-level Transform Ruleset", - "description": "Zone-level ruleset that will execute Transform Rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "rewrite", - "action_parameters": { - "uri": { - "path": { - "value": "/emea.html" - } - } - }, - "expression": "(http.request.uri.query contains \"eu\")", - "description": "My first static rewrite URL rule", - "last_updated": "2021-04-14T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2021-04-14T14:42:04.219025Z", - "phase": "http_request_transform" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Zone-level Transform Ruleset", + "description": "Zone-level ruleset that will execute Transform Rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "rewrite", + "action_parameters": { + "uri": { + "path": { + "value": "/emea.html" + } + } + }, + "expression": "(http.request.uri.query contains \"eu\")", + "description": "My first static rewrite URL rule", + "last_updated": "2021-04-14T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2021-04-14T14:42:04.219025Z", + "phase": "http_request_transform" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-
-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/operations/updateZoneRuleset) operation: +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/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated. -```bash title="Request" +```bash curl --request PUT \ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ --header "Authorization: Bearer " \ @@ -125,51 +122,48 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -The response contains the complete definition of the ruleset you updated. - -```json title="Response" +```json output { - "result": { - "id": "", - "name": "Zone-level Transform Ruleset", - "description": "Zone-level ruleset that will execute Transform Rules.", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "", - "version": "1", - "action": "rewrite", - "action_parameters": { - "uri": { - "path": { - "expression": "concat(\"/archive\", http.request.uri.path)" - } - } - }, - "expression": "starts_with(http.request.uri.path, \"/news/2012/\")", - "description": "My first dynamic rewrite URL rule", - "last_updated": "2021-04-14T14:42:04.219025Z", - "ref": "" - } - ], - "last_updated": "2021-04-14T14:42:04.219025Z", - "phase": "http_request_transform" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "", + "name": "Zone-level Transform Ruleset", + "description": "Zone-level ruleset that will execute Transform Rules.", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "", + "version": "1", + "action": "rewrite", + "action_parameters": { + "uri": { + "path": { + "expression": "concat(\"/archive\", http.request.uri.path)" + } + } + }, + "expression": "starts_with(http.request.uri.path, \"/news/2012/\")", + "description": "My first dynamic rewrite URL rule", + "last_updated": "2021-04-14T14:42:04.219025Z", + "ref": "" + } + ], + "last_updated": "2021-04-14T14:42:04.219025Z", + "phase": "http_request_transform" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-*** +--- ## Required API token permissions The API token used in API requests to manage rewrite URL rules must have at least the following permissions: -* *Account* > *Transform Rules* > *Edit* -* *Account* > *Account Rulesets* > *Read* +- _Account_ > _Transform Rules_ > _Edit_ +- _Account_ > _Account Rulesets_ > _Read_ 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 67caf0ba440d95f..fd259ef0edbddf6 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,10 +7,9 @@ head: - tag: title content: Create Bulk Redirects via API description: Learn how to create Bulk Redirects using the Cloudflare API. - --- -import { Render } from "~/components" +import { Render } from "~/components"; To create Bulk Redirects via API, you must: @@ -18,13 +17,16 @@ To create Bulk Redirects via API, you must: 2. Add items (URL redirects) to the list created in step 1. 3. Create a Bulk Redirect Rule via API, which enables the list created in step 1. - + ## 1. Create a Bulk Redirect List via API Use the [Create a list](/api/operations/lists-create-a-list) operation to create a new Bulk Redirect List. The list `kind` must be `redirect`. -```bash title="Request" +```bash curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists \ --header "Authorization: Bearer " \ --header "Content-Type: application/json" \ @@ -35,23 +37,21 @@ curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists \ }' ``` -The response will be similar to the following: - -```json title="Response" {3} +```json output {3} { - "result": { - "id": "f848b6ccb07647749411f504d6f88794", - "name": "my_redirect_list", - "description": "My redirect list.", - "kind": "redirect", - "num_items": 0, - "num_referencing_filters": 0, - "created_on": "2021-10-28T09:11:42Z", - "modified_on": "2021-10-28T09:11:42Z" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "f848b6ccb07647749411f504d6f88794", + "name": "my_redirect_list", + "description": "My redirect list.", + "kind": "redirect", + "num_items": 0, + "num_referencing_filters": 0, + "created_on": "2021-10-28T09:11:42Z", + "modified_on": "2021-10-28T09:11:42Z" + }, + "success": true, + "errors": [], + "messages": [] } ``` @@ -63,7 +63,7 @@ For more information on list operations, refer to the [Lists API](/waf/tools/lis Use the [Create list items](/api/operations/lists-create-list-items) operation to add URL redirect items to the list. Enter the list ID from the previous step in the endpoint URL: -```bash title="Request" +```bash curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists/f848b6ccb07647749411f504d6f88794/items \ --header "Authorization: Bearer " \ --header "Content-Type: application/json" \ @@ -84,38 +84,36 @@ curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists/f848 ]' ``` -The response will be similar to the following: - -```json title="Response" +```json output { - "result": { - "operation_id": "92558f8b296d4dbe9d0419e0e53f6622" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "operation_id": "92558f8b296d4dbe9d0419e0e53f6622" + }, + "success": true, + "errors": [], + "messages": [] } ``` 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/operations/lists-get-bulk-operation-status) operation: -```bash title="Request" +```bash curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists/bulk_operations/92558f8b296d4dbe9d0419e0e53f6622 \ --header "Authorization: Bearer " ``` -If the operation already completed successfully, the response will be similar to the following: +Once the operation has completed successfully, the response will be similar to the following: ```json title="Response" { - "result": { - "id": "92558f8b296d4dbe9d0419e0e53f6622", - "status": "completed", - "completed": "2021-10-28T09:15:42Z" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "92558f8b296d4dbe9d0419e0e53f6622", + "status": "completed", + "completed": "2021-10-28T09:15:42Z" + }, + "success": true, + "errors": [], + "messages": [] } ``` @@ -127,12 +125,12 @@ Add Bulk Redirect Rules to the [entry point ruleset](/ruleset-engine/about/rules A Bulk Redirect Rule must have: -* `action` set to `redirect` -* An `action_parameters` object with additional configuration settings — refer to [API JSON objects: Bulk Redirect Rule](/rules/url-forwarding/bulk-redirects/reference/json-objects/#bulk-redirect-rule) for details. +- `action` set to `redirect` +- An `action_parameters` object with additional configuration settings — refer to [API JSON objects: Bulk Redirect Rule](/rules/url-forwarding/bulk-redirects/reference/json-objects/#bulk-redirect-rule) for details. The following request of the [Create an account ruleset](/api/operations/createAccountRuleset) 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 title="Request" +```bash curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets \ --header "Authorization: Bearer " \ --header "Content-Type: application/json" \ @@ -156,45 +154,43 @@ curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets \ }' ``` -The response will be similar to the following: - -```json title="Response" +```json output { - "result": { - "id": "528f4f03bf0da53a29907199625867be", - "name": "My redirect ruleset", - "kind": "root", - "version": "1", - "rules": [ - { - "id": "8da312df846b4258a05bcd454ea943be", - "version": "1", - "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" - } - }, - "last_updated": "2021-10-28T09:20:42Z", - } - ], - "last_updated": "2021-10-28T09:20:42Z", - "phase": "http_request_redirect" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "528f4f03bf0da53a29907199625867be", + "name": "My redirect ruleset", + "kind": "root", + "version": "1", + "rules": [ + { + "id": "8da312df846b4258a05bcd454ea943be", + "version": "1", + "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" + } + }, + "last_updated": "2021-10-28T09:20:42Z" + } + ], + "last_updated": "2021-10-28T09:20:42Z", + "phase": "http_request_redirect" + }, + "success": true, + "errors": [], + "messages": [] } ``` If there is already a phase entry point ruleset for the `http_request_redirect` phase, use the [Update an account ruleset](/api/operations/updateAccountRuleset) operation instead, like in the following example: -```bash title="Request" +```bash curl --request PUT \ -https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{ruleset_id} \ +"https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{ruleset_id}" \ --header "Authorization: Bearer " \ --header "Content-Type: application/json" \ --data '{ @@ -228,64 +224,62 @@ https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{ruleset_id} }' ``` -The response will be similar to the following: - -```json title="Response" +```json output { - "result": { - "id": "67013aa153df4e5fbda92f92bc979331", - "name": "default", - "description": "", - "kind": "root", - "version": "2", - "rules": [ - { - "id": "8be62ab2ef9a4a41af30c24ff8e73e41", - "version": "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_1", - "description": "Bulk Redirect rule 1", - "last_updated": "2021-12-03T15:38:51.658387Z", - "ref": "8be62ab2ef9a4a41af30c24ff8e73e41", - "enabled": true - }, - { - "id": "97e38797fb2b4b22a4919800f1318a5c", - "version": "1", - "action": "redirect", - "action_parameters": { - "from_list": { - "name": "my_redirect_list_2", - "key": "http.request.full_uri" - } - }, - "expression": "http.request.full_uri in $my_redirect_list_2", - "description": "Bulk Redirect rule 2", - "last_updated": "2021-12-03T15:38:51.658387Z", - "ref": "97e38797fb2b4b22a4919800f1318a5c", - "enabled": true - } - ], - "last_updated": "2021-12-03T15:38:51.658387Z", - "phase": "http_request_redirect" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "67013aa153df4e5fbda92f92bc979331", + "name": "default", + "description": "", + "kind": "root", + "version": "2", + "rules": [ + { + "id": "8be62ab2ef9a4a41af30c24ff8e73e41", + "version": "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_1", + "description": "Bulk Redirect rule 1", + "last_updated": "2021-12-03T15:38:51.658387Z", + "ref": "8be62ab2ef9a4a41af30c24ff8e73e41", + "enabled": true + }, + { + "id": "97e38797fb2b4b22a4919800f1318a5c", + "version": "1", + "action": "redirect", + "action_parameters": { + "from_list": { + "name": "my_redirect_list_2", + "key": "http.request.full_uri" + } + }, + "expression": "http.request.full_uri in $my_redirect_list_2", + "description": "Bulk Redirect rule 2", + "last_updated": "2021-12-03T15:38:51.658387Z", + "ref": "97e38797fb2b4b22a4919800f1318a5c", + "enabled": true + } + ], + "last_updated": "2021-12-03T15:38:51.658387Z", + "phase": "http_request_redirect" + }, + "success": true, + "errors": [], + "messages": [] } ``` -*** +--- ## Required API token permissions The API token used in API requests to manage Bulk Redirects objects (lists, list items, and rules) must have at least the following permissions: -* *Account* > *Account Rulesets* > *Edit* -* *Account* > *Account Filter Lists* > *Edit* +- _Account_ > _Account Rulesets_ > _Edit_ +- _Account_ > _Account Filter Lists_ > _Edit_ 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 d9928f7cc2fbdef..14fe18604572f16 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,23 +6,25 @@ sidebar: head: - tag: title content: Create a redirect rule via API - --- -import { Details, Render } from "~/components" +import { Details, Render } from "~/components"; Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create a redirect rule via API. Add redirect rules to the entry point ruleset of the `http_request_dynamic_redirect` phase at the zone level. Refer to the [Rulesets API](/ruleset-engine/rulesets-api/) documentation for more information on [creating a ruleset](/ruleset-engine/rulesets-api/create/) and supplying a list of rules for the ruleset. - + ## Basic rule settings A redirect rule must have: -* `action` set to `redirect` -* An `action_parameters` object with additional configuration settings — refer to [Available settings](/rules/url-forwarding/single-redirects/settings/) for details. +- `action` set to `redirect` +- An `action_parameters` object with additional configuration settings — refer to [Available settings](/rules/url-forwarding/single-redirects/settings/) for details. ## Example requests @@ -55,45 +57,43 @@ curl https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets \ }' ``` -
```json { - "result": { - "id": "528f4f03bf0da53a29907199625867be", - "name": "Redirect rules ruleset", - "kind": "zone", - "version": "1", - "rules": [ - { - "id": "235e557b92fd4e5e8753ee665a9ddd75", - "version": "1", - "expression": "(ip.geoip.country eq \"GB\" or ip.geoip.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.geoip.country, \".example.com\"))" - }, - "status_code": 307, - "preserve_query_string": true - } - }, - "last_updated": "2022-09-28T09:20:42Z", - } - ], - "last_updated": "2022-09-28T09:20:42Z", - "phase": "http_request_dynamic_redirect" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "528f4f03bf0da53a29907199625867be", + "name": "Redirect rules ruleset", + "kind": "zone", + "version": "1", + "rules": [ + { + "id": "235e557b92fd4e5e8753ee665a9ddd75", + "version": "1", + "expression": "(ip.geoip.country eq \"GB\" or ip.geoip.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.geoip.country, \".example.com\"))" + }, + "status_code": 307, + "preserve_query_string": true + } + }, + "last_updated": "2022-09-28T09:20:42Z" + } + ], + "last_updated": "2022-09-28T09:20:42Z", + "phase": "http_request_dynamic_redirect" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
If there is already a phase entry point ruleset for the `http_request_dynamic_redirect` phase, use the [Update a zone ruleset](/api/operations/updateZoneRuleset) operation instead, like in the following example: @@ -139,72 +139,70 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \ }' ``` -
```json { - "result": { - "id": "528f4f03bf0da53a29907199625867be", - "name": "Redirect rules ruleset", - "description": "", - "kind": "zone", - "version": "2", - "rules": [ - { - "id": "235e557b92fd4e5e8753ee665a9ddd75", - "version": "1", - "action": "redirect", - "action_parameters": { - "from_value": { - "target_url": { - "expression": "lower(concat(\"https://\", ip.geoip.country, \".example.com\"))" - }, - "status_code": 307, - "preserve_query_string": true - } - }, - "expression": "(ip.geoip.country eq \"GB\" or ip.geoip.country eq \"FR\") and http.request.uri.path eq \"/\"", - "description": "Redirect GB and FR users in home page to localized site.", - "last_updated": "2022-10-03T15:38:51.658387Z", - "ref": "235e557b92fd4e5e8753ee665a9ddd75", - "enabled": true - }, - { - "id": "cfad5efbfcd1440fb5b30cf30f95ece3", - "version": "1", - "action": "redirect", - "action_parameters": { - "from_value": { - "target_url": { - "value": "https://example.com/contact-us/" - }, - "status_code": 308 - } - }, - "expression": "http.request.uri.path eq \"/contacts.html\"", - "description": "Redirect to new contacts page.", - "last_updated": "2022-10-03T15:38:51.658387Z", - "ref": "cfad5efbfcd1440fb5b30cf30f95ece3", - "enabled": true - } - ], - "last_updated": "2022-10-03T15:38:51.658387Z", - "phase": "http_request_dynamic_redirect" - }, - "success": true, - "errors": [], - "messages": [] + "result": { + "id": "528f4f03bf0da53a29907199625867be", + "name": "Redirect rules ruleset", + "description": "", + "kind": "zone", + "version": "2", + "rules": [ + { + "id": "235e557b92fd4e5e8753ee665a9ddd75", + "version": "1", + "action": "redirect", + "action_parameters": { + "from_value": { + "target_url": { + "expression": "lower(concat(\"https://\", ip.geoip.country, \".example.com\"))" + }, + "status_code": 307, + "preserve_query_string": true + } + }, + "expression": "(ip.geoip.country eq \"GB\" or ip.geoip.country eq \"FR\") and http.request.uri.path eq \"/\"", + "description": "Redirect GB and FR users in home page to localized site.", + "last_updated": "2022-10-03T15:38:51.658387Z", + "ref": "235e557b92fd4e5e8753ee665a9ddd75", + "enabled": true + }, + { + "id": "cfad5efbfcd1440fb5b30cf30f95ece3", + "version": "1", + "action": "redirect", + "action_parameters": { + "from_value": { + "target_url": { + "value": "https://example.com/contact-us/" + }, + "status_code": 308 + } + }, + "expression": "http.request.uri.path eq \"/contacts.html\"", + "description": "Redirect to new contacts page.", + "last_updated": "2022-10-03T15:38:51.658387Z", + "ref": "cfad5efbfcd1440fb5b30cf30f95ece3", + "enabled": true + } + ], + "last_updated": "2022-10-03T15:38:51.658387Z", + "phase": "http_request_dynamic_redirect" + }, + "success": true, + "errors": [], + "messages": [] } ``` -
-*** +--- ## Required API token permissions The API token used in API requests to manage redirect rules must have at least the following permission: -* *Zone* > *Single Redirect* > *Edit* +- _Zone_ > _Single Redirect_ > _Edit_