|
| 1 | +--- |
| 2 | +title: Configure via API |
| 3 | +pcx_content_type: how-to |
| 4 | +weight: 3 |
| 5 | +meta: |
| 6 | + title: Configure a Cloud Connector rule via API |
| 7 | +--- |
| 8 | + |
| 9 | +# Configure a rule via API |
| 10 | + |
| 11 | +You can configure Cloud Connector rules using the [Cloudflare API](/fundamentals/api/). |
| 12 | + |
| 13 | +## Required permissions |
| 14 | + |
| 15 | +The [API token](/fundamentals/api/get-started/create-token/) used in API requests to manage Cloud Connector rules must have at least the following permission: |
| 16 | + |
| 17 | +- _Zone_ > _Cloud Connector_ > _Write_ |
| 18 | + |
| 19 | +{{<Aside type="note" header="Note">}} |
| 20 | +A token with this permission is only valid for the Cloud Connector endpoints described in this page. You cannot use it to interact with the `http_cloud_connector` phase via [Rulesets API](/ruleset-engine/rulesets-api/). |
| 21 | +{{</Aside>}} |
| 22 | + |
| 23 | +## Endpoints |
| 24 | + |
| 25 | +To obtain the complete endpoint, append the Cloud Connector endpoints listed below to the Cloudflare API base URL: |
| 26 | + |
| 27 | +```txt |
| 28 | +https://api.cloudflare.com/client/v4 |
| 29 | +``` |
| 30 | + |
| 31 | +The `{zone_id}` argument is the [zone ID](/fundamentals/setup/find-account-and-zone-ids/) (a hexadecimal string). You can find this value in the Cloudflare dashboard. |
| 32 | + |
| 33 | +The following table summarizes the available operations. |
| 34 | + |
| 35 | +Operation | Verb + Endpoint |
| 36 | +----------|---------------- |
| 37 | +List Cloud Connector rules | `GET zones/{zone_id}/cloud_connector/rules` |
| 38 | +Create/update/delete Cloud Connector rules | `PUT /zones/{zone_id}/cloud_connector/rules` |
| 39 | + |
| 40 | +## Example API calls |
| 41 | + |
| 42 | +### List of Cloud Connector rules |
| 43 | + |
| 44 | +The following example returns a list of existing Cloud Connector rules: |
| 45 | + |
| 46 | +```bash |
| 47 | +curl https://api.cloudflare.com/client/v4/zones/{zone_id}/cloud_connector/rules \ |
| 48 | +--header "Authorization: Bearer <API_TOKEN>" |
| 49 | +``` |
| 50 | + |
| 51 | +```json |
| 52 | +--- |
| 53 | +header: Example response |
| 54 | +--- |
| 55 | +{ |
| 56 | + "result": [ |
| 57 | + { |
| 58 | + "id": "<RULE_1_ID>", |
| 59 | + "provider": "aws_s3", |
| 60 | + "expression": "http.request.uri.path wildcard \"/images/*\"", |
| 61 | + "description": "Connect to S3 bucket containing images", |
| 62 | + "enabled": true, |
| 63 | + "parameters": { |
| 64 | + "host": "examplebucketwithimages.s3.north-eu.amazonaws.com" |
| 65 | + } |
| 66 | + }, |
| 67 | + { |
| 68 | + "id": "<RULE_2_ID>", |
| 69 | + "provider": "cloudflare_r2", |
| 70 | + "expression": "http.request.uri.path wildcard \"/videos/*\"", |
| 71 | + "description": "Connect to R2 bucket containing videos", |
| 72 | + "enabled": true, |
| 73 | + "parameters": { |
| 74 | + "host": "mybucketcustomdomain.example.com" |
| 75 | + } |
| 76 | + } |
| 77 | + ], |
| 78 | + "success": true, |
| 79 | + "errors": [], |
| 80 | + "messages": [] |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### Create/update/delete Cloud Connector rules |
| 85 | + |
| 86 | +The following example request will replace all existing Cloud Connector rules with a single rule: |
| 87 | + |
| 88 | +```bash |
| 89 | +curl --request PUT \ |
| 90 | +"https://api.cloudflare.com/client/v4/zones/{zone_id}/cloud_connector/rules" \ |
| 91 | +--header "Authorization: Bearer <API_TOKEN>" \ |
| 92 | +--header "Content-Type: application/json" \ |
| 93 | +--data '[ |
| 94 | + { |
| 95 | + "expression": "http.request.uri.path wildcard \"/images/*\"", |
| 96 | + "provider": "aws_s3", |
| 97 | + "description": "Connect to S3 bucket containing images", |
| 98 | + "parameters": { |
| 99 | + "host": "examplebucketwithimages.s3.north-eu.amazonaws.com" |
| 100 | + } |
| 101 | + } |
| 102 | +]' |
| 103 | +``` |
| 104 | + |
| 105 | +The required body parameters for each rule are: `expression`, `provider`, and `parameters.host`. |
| 106 | + |
| 107 | +The `provider` value must be one of the following: `aws_s3`, `azure_storage`, `gcp_storage`, and `cloudflare_r2`. |
| 108 | + |
| 109 | +{{<Aside type="warning" header="Warning">}} |
| 110 | +To create a new rule and keep all existing rules, you must include them all in your request body. Omitting an existing rule in the request body will delete the corresponding Cloud Connector rule. |
| 111 | +{{</Aside>}} |
0 commit comments