How do I translate what I'm seeing in the Dashboard into some API calls...?

What is the name of the domain?

example.com

What is the error number?

N/A

What is the error message?

N/A

What is the issue you’re encountering

I’m attempting to map my manually created resources in the Cloudflare Dashboard to ultimately import into Terraform. I’m confused by what I’m seeing named in the Dashboard, and not being able to find it in curl.

What steps have you taken to resolve the issue?

I’ve attempted to locate documentation on the Developers documentation but have overlooked something and am confused on the object types.

What are the steps to reproduce the issue?

(The initial post limits the number of links, so I’ve had to introduce some placeholder text.)

To describe what I am looking at in the Dashboard, on https://dash.cloudflare.com/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bulk-redirects

Underneath a “Single Redirects” tab I see:
“+ Create rule” button
Order: 1
Name: “Canonical redirect (root domain to www.)”
Enabled? Yes
Where, when this link is clicked, it goes to: /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/example.com/rules/redirect-rules/rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

And underneath a “Bulk Redirects” tab I see:

Section 1 - “Bulk Redirects”:
“+ Bulk Redirect Rule” button
Order: 1
Rule Name: “[Example] Redirect Pages to WWW”
Where, when this link is clicked, it goes to: /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bulk-redirects/redirect-rule/rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

Section 2 - “Bulk Redirect Lists”:
Associated List: “example_bulk_redirects”
Enabled? Yes

“Bulk Redirect Lists”
List Name: “example_bulk_redirects”
description:
Number of Redirects: 1
Status: “Active”

Where, when this link is clicked, it goes to: /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bulk-redirects/redirect-list/llllllllllllllllllllllllllllllll/edit-redirects

  1. Where do I find “[Example] Redirect Pages to WWW” in the documentation/curl command(s)?
  2. Where do I find “Canonical redirect (root domain to www.)” in the documentation/curl command(s)? (https://dash.cloudflare.com/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/example.com/rules/redirect-rules)

Thank you.

First, I set some environment variables for my shell:

export CLOUDFLARE_EMAIL='[email protected]'
export CLOUDFLARE_ZONE_ID='zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'
export CLOUDFLARE_ACCOUNT_ID='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
export CLOUDFLARE_API_TOKEN='tttttttttttttttttttttttttttttttt'

Command 1 - is successful:

curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
     -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
     -H "Content-Type:application/json"

Command 2:

curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/rules/lists \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  -H "Content-Type: application/json"

Returns:

{
  "result": [
    {
      "id": "llllllllllllllllllllllllllllllll",
      "name": "example_bulk_redirects",
      "kind": "redirect",
      "num_items": 1,
      "num_referencing_filters": 0,
      "created_on": "2024-12-12T12:34:56Z",
      "modified_on": "2024-12-12T12:34:56Z"
    }
  ],
  "success": true,
  "errors": [],
  "messages": []
}

Command 3:

curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/rules/lists/llllllllllllllllllllllllllllllll \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  -H "Content-Type:application/json"

Returns:

{
  "result": [
    {
      "id": "llllllllllllllllllllllllllllllll",
      "name": "example_bulk_redirects",
      "kind": "redirect",
      "num_items": 1,
      "num_referencing_filters": 0,
      "created_on": "2024-12-12T12:34:56Z",
      "modified_on": "2024-12-12T12:34:56Z"
    }
  ],
  "success": true,
  "errors": [],
  "messages": []
}

Command 4:

curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/rules/lists/llllllllllllllllllllllllllllllll/items \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  -H "Content-Type:application/json"

Returns:

{
  "result": [
    {
      "id": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",
      "redirect": {
        "source_url": "example.pages.dev/",
        "include_subdomains": true,
        "target_url": "https://www.example.com",
        "status_code": 301,
        "preserve_query_string": true,
        "subpath_matching": true,
        "preserve_path_suffix": true
      },
      "created_on": "2024-12-12T12:34:56Z",
      "modified_on": "2024-12-12T12:34:56Z"
    }
  ],
  "success": true,
  "errors": [],
  "messages": []
}

Command 5:

curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/rules/lists/llllllllllllllllllllllllllllllll/items/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  -H "Content-Type:application/json"

Returns:

{
  "result": {
    "id": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",
    "redirect": {
      "source_url": "example.pages.dev/",
      "include_subdomains": true,
      "target_url": "https://www.example.com",
      "status_code": 301,
      "preserve_query_string": true,
      "subpath_matching": true,
      "preserve_path_suffix": true
    },
    "created_on": "2024-12-12T12:34:56Z",
    "modified_on": "2024-12-12T12:34:56Z"
  },
  "success": true,
  "errors": [],
  "messages": []
}

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.