Skip to content
Start here

List account or zone routing rules

client.EmailRouting.AccountRules.List(ctx, params) (*V4PagePaginationArray[AccountRule], error)
GET/{accounts_or_zones}/{account_or_zone_id}/email/routing/rules

Lists existing routing rules across all zones in the account or zone.

Security

API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
ParametersExpand Collapse
params AccountRuleListParams
AccountID param.Field[string]Optional

Path param: The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.

ZoneID param.Field[string]Optional

Path param: The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.

Enabled param.Field[AccountRuleListParamsEnabled]Optional

Query param: Filter by enabled routing rules.

const AccountRuleListParamsEnabledTrue AccountRuleListParamsEnabled = true
const AccountRuleListParamsEnabledFalse AccountRuleListParamsEnabled = false
Page param.Field[float64]Optional

Query param: Page number of paginated results.

minimum1
PerPage param.Field[float64]Optional

Query param: Maximum number of results per page.

maximum50
minimum5
ReturnsExpand Collapse
type AccountRule struct{…}
ID stringOptional

Routing rule identifier.

maxLength32
Actions []ActionOptional

List actions patterns.

Type ActionType

Type of supported action.

One of the following:
const ActionTypeDrop ActionType = "drop"
const ActionTypeForward ActionType = "forward"
const ActionTypeWorker ActionType = "worker"
Value []stringOptional
Enabled AccountRuleEnabledOptional

Routing rule status.

One of the following:
const AccountRuleEnabledTrue AccountRuleEnabled = true
const AccountRuleEnabledFalse AccountRuleEnabled = false
Matchers []MatcherOptional

Matching patterns to forward to your actions.

Type MatcherType

Type of matcher.

One of the following:
const MatcherTypeAll MatcherType = "all"
const MatcherTypeLiteral MatcherType = "literal"
Field MatcherFieldOptional

Field for type matcher.

Value stringOptional

Value for matcher.

maxLength90
Name stringOptional

Routing rule name.

maxLength256
Priority float64Optional

Priority of the routing rule.

minimum0
Source AccountRuleSourceOptional

Who manages the rule. api covers dashboard, generic API, and Terraform; wrangler means the rule is managed by a Worker’s wrangler.jsonc. Defaults to api when omitted on write.

One of the following:
const AccountRuleSourceAPI AccountRuleSource = "api"
const AccountRuleSourceWrangler AccountRuleSource = "wrangler"
DeprecatedTag stringOptional

Routing rule tag. (Deprecated, replaced by routing rule identifier)

maxLength32
Zone AccountRuleZoneOptional

Zone information for the routing rule.

Name stringOptional

Zone name.

Tag stringOptional

Zone tag.

maxLength32

List account or zone routing rules

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/email_routing"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
    option.WithAPIEmail("user@example.com"),
  )
  page, err := client.EmailRouting.AccountRules.List(context.TODO(), email_routing.AccountRuleListParams{

  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": [
    {
      "id": "a7e6fb77503c41d8a7f3113c6918f10c",
      "actions": [
        {
          "type": "forward",
          "value": [
            "destinationaddress@example.net"
          ]
        }
      ],
      "enabled": true,
      "matchers": [
        {
          "type": "literal",
          "field": "to",
          "value": "test@example.com"
        }
      ],
      "name": "Send to user@example.net rule.",
      "priority": 0,
      "source": "api",
      "tag": "a7e6fb77503c41d8a7f3113c6918f10c",
      "zone": {
        "name": "example.com",
        "tag": "023e105f4ecef8ad9ca31a8372d0c353"
      }
    }
  ],
  "result_info": {
    "count": 1,
    "page": 1,
    "per_page": 20,
    "total_count": 1,
    "total_pages": 100
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": [
    {
      "id": "a7e6fb77503c41d8a7f3113c6918f10c",
      "actions": [
        {
          "type": "forward",
          "value": [
            "destinationaddress@example.net"
          ]
        }
      ],
      "enabled": true,
      "matchers": [
        {
          "type": "literal",
          "field": "to",
          "value": "test@example.com"
        }
      ],
      "name": "Send to user@example.net rule.",
      "priority": 0,
      "source": "api",
      "tag": "a7e6fb77503c41d8a7f3113c6918f10c",
      "zone": {
        "name": "example.com",
        "tag": "023e105f4ecef8ad9ca31a8372d0c353"
      }
    }
  ],
  "result_info": {
    "count": 1,
    "page": 1,
    "per_page": 20,
    "total_count": 1,
    "total_pages": 100
  }
}