# Rules ## List routing rules `client.emailRouting.rules.list(RuleListParamsparams, RequestOptionsoptions?): V4PagePaginationArray` **get** `/zones/{zone_id}/email/routing/rules` Lists existing routing rules. ### Parameters - `params: RuleListParams` - `zone_id: string` Path param: Identifier. - `enabled?: true | false` Query param: Filter by enabled routing rules. - `true` - `false` - `page?: number` Query param: Page number of paginated results. - `per_page?: number` Query param: Maximum number of results per page. ### Returns - `EmailRoutingRule` - `id?: string` Routing rule identifier. - `actions?: Array` List actions patterns. - `type: "drop" | "forward" | "worker"` Type of supported action. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `enabled?: true | false` Routing rule status. - `true` - `false` - `matchers?: Array` Matching patterns to forward to your actions. - `type: "all" | "literal"` Type of matcher. - `"all"` - `"literal"` - `field?: "to"` Field for type matcher. - `"to"` - `value?: string` Value for matcher. - `name?: string` Routing rule name. - `priority?: number` Priority of the routing rule. - `tag?: string` Routing rule tag. (Deprecated, replaced by routing rule identifier) ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const emailRoutingRule of client.emailRouting.rules.list({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353', })) { console.log(emailRoutingRule.id); } ``` #### Response ```json { "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, "tag": "a7e6fb77503c41d8a7f3113c6918f10c" } ], "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 1, "total_pages": 100 } } ``` ## Get routing rule `client.emailRouting.rules.get(stringruleIdentifier, RuleGetParamsparams, RequestOptionsoptions?): EmailRoutingRule` **get** `/zones/{zone_id}/email/routing/rules/{rule_identifier}` Get information for a specific routing rule already created. ### Parameters - `ruleIdentifier: string` Routing rule identifier. - `params: RuleGetParams` - `zone_id: string` Identifier. ### Returns - `EmailRoutingRule` - `id?: string` Routing rule identifier. - `actions?: Array` List actions patterns. - `type: "drop" | "forward" | "worker"` Type of supported action. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `enabled?: true | false` Routing rule status. - `true` - `false` - `matchers?: Array` Matching patterns to forward to your actions. - `type: "all" | "literal"` Type of matcher. - `"all"` - `"literal"` - `field?: "to"` Field for type matcher. - `"to"` - `value?: string` Value for matcher. - `name?: string` Routing rule name. - `priority?: number` Priority of the routing rule. - `tag?: string` Routing rule tag. (Deprecated, replaced by routing rule identifier) ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const emailRoutingRule = await client.emailRouting.rules.get('a7e6fb77503c41d8a7f3113c6918f10c', { zone_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(emailRoutingRule.id); ``` #### Response ```json { "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, "tag": "a7e6fb77503c41d8a7f3113c6918f10c" } } ``` ## Create routing rule `client.emailRouting.rules.create(RuleCreateParamsparams, RequestOptionsoptions?): EmailRoutingRule` **post** `/zones/{zone_id}/email/routing/rules` Rules consist of a set of criteria for matching emails (such as an email being sent to a specific custom email address) plus a set of actions to take on the email (like forwarding it to a specific destination address). ### Parameters - `params: RuleCreateParams` - `zone_id: string` Path param: Identifier. - `actions: Array` Body param: List actions patterns. - `type: "drop" | "forward" | "worker"` Type of supported action. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `matchers: Array` Body param: Matching patterns to forward to your actions. - `type: "all" | "literal"` Type of matcher. - `"all"` - `"literal"` - `field?: "to"` Field for type matcher. - `"to"` - `value?: string` Value for matcher. - `enabled?: true | false` Body param: Routing rule status. - `true` - `false` - `name?: string` Body param: Routing rule name. - `priority?: number` Body param: Priority of the routing rule. ### Returns - `EmailRoutingRule` - `id?: string` Routing rule identifier. - `actions?: Array` List actions patterns. - `type: "drop" | "forward" | "worker"` Type of supported action. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `enabled?: true | false` Routing rule status. - `true` - `false` - `matchers?: Array` Matching patterns to forward to your actions. - `type: "all" | "literal"` Type of matcher. - `"all"` - `"literal"` - `field?: "to"` Field for type matcher. - `"to"` - `value?: string` Value for matcher. - `name?: string` Routing rule name. - `priority?: number` Priority of the routing rule. - `tag?: string` Routing rule tag. (Deprecated, replaced by routing rule identifier) ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const emailRoutingRule = await client.emailRouting.rules.create({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353', actions: [{ type: 'forward' }], matchers: [{ type: 'literal' }], }); console.log(emailRoutingRule.id); ``` #### Response ```json { "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, "tag": "a7e6fb77503c41d8a7f3113c6918f10c" } } ``` ## Update routing rule `client.emailRouting.rules.update(stringruleIdentifier, RuleUpdateParamsparams, RequestOptionsoptions?): EmailRoutingRule` **put** `/zones/{zone_id}/email/routing/rules/{rule_identifier}` Update actions and matches, or enable/disable specific routing rules. ### Parameters - `ruleIdentifier: string` Routing rule identifier. - `params: RuleUpdateParams` - `zone_id: string` Path param: Identifier. - `actions: Array` Body param: List actions patterns. - `type: "drop" | "forward" | "worker"` Type of supported action. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `matchers: Array` Body param: Matching patterns to forward to your actions. - `type: "all" | "literal"` Type of matcher. - `"all"` - `"literal"` - `field?: "to"` Field for type matcher. - `"to"` - `value?: string` Value for matcher. - `enabled?: true | false` Body param: Routing rule status. - `true` - `false` - `name?: string` Body param: Routing rule name. - `priority?: number` Body param: Priority of the routing rule. ### Returns - `EmailRoutingRule` - `id?: string` Routing rule identifier. - `actions?: Array` List actions patterns. - `type: "drop" | "forward" | "worker"` Type of supported action. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `enabled?: true | false` Routing rule status. - `true` - `false` - `matchers?: Array` Matching patterns to forward to your actions. - `type: "all" | "literal"` Type of matcher. - `"all"` - `"literal"` - `field?: "to"` Field for type matcher. - `"to"` - `value?: string` Value for matcher. - `name?: string` Routing rule name. - `priority?: number` Priority of the routing rule. - `tag?: string` Routing rule tag. (Deprecated, replaced by routing rule identifier) ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const emailRoutingRule = await client.emailRouting.rules.update( 'a7e6fb77503c41d8a7f3113c6918f10c', { zone_id: '023e105f4ecef8ad9ca31a8372d0c353', actions: [{ type: 'forward' }], matchers: [{ type: 'literal' }], }, ); console.log(emailRoutingRule.id); ``` #### Response ```json { "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, "tag": "a7e6fb77503c41d8a7f3113c6918f10c" } } ``` ## Delete routing rule `client.emailRouting.rules.delete(stringruleIdentifier, RuleDeleteParamsparams, RequestOptionsoptions?): EmailRoutingRule` **delete** `/zones/{zone_id}/email/routing/rules/{rule_identifier}` Delete a specific routing rule. ### Parameters - `ruleIdentifier: string` Routing rule identifier. - `params: RuleDeleteParams` - `zone_id: string` Identifier. ### Returns - `EmailRoutingRule` - `id?: string` Routing rule identifier. - `actions?: Array` List actions patterns. - `type: "drop" | "forward" | "worker"` Type of supported action. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `enabled?: true | false` Routing rule status. - `true` - `false` - `matchers?: Array` Matching patterns to forward to your actions. - `type: "all" | "literal"` Type of matcher. - `"all"` - `"literal"` - `field?: "to"` Field for type matcher. - `"to"` - `value?: string` Value for matcher. - `name?: string` Routing rule name. - `priority?: number` Priority of the routing rule. - `tag?: string` Routing rule tag. (Deprecated, replaced by routing rule identifier) ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const emailRoutingRule = await client.emailRouting.rules.delete( 'a7e6fb77503c41d8a7f3113c6918f10c', { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, ); console.log(emailRoutingRule.id); ``` #### Response ```json { "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, "tag": "a7e6fb77503c41d8a7f3113c6918f10c" } } ``` ## Domain Types ### Action - `Action` Actions pattern. - `type: "drop" | "forward" | "worker"` Type of supported action. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` ### Email Routing Rule - `EmailRoutingRule` - `id?: string` Routing rule identifier. - `actions?: Array` List actions patterns. - `type: "drop" | "forward" | "worker"` Type of supported action. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `enabled?: true | false` Routing rule status. - `true` - `false` - `matchers?: Array` Matching patterns to forward to your actions. - `type: "all" | "literal"` Type of matcher. - `"all"` - `"literal"` - `field?: "to"` Field for type matcher. - `"to"` - `value?: string` Value for matcher. - `name?: string` Routing rule name. - `priority?: number` Priority of the routing rule. - `tag?: string` Routing rule tag. (Deprecated, replaced by routing rule identifier) ### Matcher - `Matcher` Matching pattern to forward your actions. - `type: "all" | "literal"` Type of matcher. - `"all"` - `"literal"` - `field?: "to"` Field for type matcher. - `"to"` - `value?: string` Value for matcher. # Catch Alls ## Get catch-all rule `client.emailRouting.rules.catchAlls.get(CatchAllGetParamsparams, RequestOptionsoptions?): CatchAllGetResponse` **get** `/zones/{zone_id}/email/routing/rules/catch_all` Get information on the default catch-all routing rule. ### Parameters - `params: CatchAllGetParams` - `zone_id: string` Identifier. ### Returns - `CatchAllGetResponse` - `id?: string` Routing rule identifier. - `actions?: Array` List actions for the catch-all routing rule. - `type: "drop" | "forward" | "worker"` Type of action for catch-all rule. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `enabled?: true | false` Routing rule status. - `true` - `false` - `matchers?: Array` List of matchers for the catch-all routing rule. - `type: "all"` Type of matcher. Default is 'all'. - `"all"` - `name?: string` Routing rule name. - `tag?: string` Routing rule tag. (Deprecated, replaced by routing rule identifier) ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const catchAll = await client.emailRouting.rules.catchAlls.get({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(catchAll.id); ``` #### Response ```json { "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": "all" } ], "name": "Send to user@example.net rule.", "tag": "a7e6fb77503c41d8a7f3113c6918f10c" } } ``` ## Update catch-all rule `client.emailRouting.rules.catchAlls.update(CatchAllUpdateParamsparams, RequestOptionsoptions?): CatchAllUpdateResponse` **put** `/zones/{zone_id}/email/routing/rules/catch_all` Enable or disable catch-all routing rule, or change action to forward to specific destination address. ### Parameters - `params: CatchAllUpdateParams` - `zone_id: string` Path param: Identifier. - `actions: Array` Body param: List actions for the catch-all routing rule. - `type: "drop" | "forward" | "worker"` Type of action for catch-all rule. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `matchers: Array` Body param: List of matchers for the catch-all routing rule. - `type: "all"` Type of matcher. Default is 'all'. - `"all"` - `enabled?: true | false` Body param: Routing rule status. - `true` - `false` - `name?: string` Body param: Routing rule name. ### Returns - `CatchAllUpdateResponse` - `id?: string` Routing rule identifier. - `actions?: Array` List actions for the catch-all routing rule. - `type: "drop" | "forward" | "worker"` Type of action for catch-all rule. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `enabled?: true | false` Routing rule status. - `true` - `false` - `matchers?: Array` List of matchers for the catch-all routing rule. - `type: "all"` Type of matcher. Default is 'all'. - `"all"` - `name?: string` Routing rule name. - `tag?: string` Routing rule tag. (Deprecated, replaced by routing rule identifier) ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const catchAll = await client.emailRouting.rules.catchAlls.update({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353', actions: [{ type: 'forward' }], matchers: [{ type: 'all' }], }); console.log(catchAll.id); ``` #### Response ```json { "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": "all" } ], "name": "Send to user@example.net rule.", "tag": "a7e6fb77503c41d8a7f3113c6918f10c" } } ``` ## Domain Types ### Catch All Action - `CatchAllAction` Action for the catch-all routing rule. - `type: "drop" | "forward" | "worker"` Type of action for catch-all rule. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` ### Catch All Matcher - `CatchAllMatcher` Matcher for catch-all routing rule. - `type: "all"` Type of matcher. Default is 'all'. - `"all"` ### Catch All Get Response - `CatchAllGetResponse` - `id?: string` Routing rule identifier. - `actions?: Array` List actions for the catch-all routing rule. - `type: "drop" | "forward" | "worker"` Type of action for catch-all rule. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `enabled?: true | false` Routing rule status. - `true` - `false` - `matchers?: Array` List of matchers for the catch-all routing rule. - `type: "all"` Type of matcher. Default is 'all'. - `"all"` - `name?: string` Routing rule name. - `tag?: string` Routing rule tag. (Deprecated, replaced by routing rule identifier) ### Catch All Update Response - `CatchAllUpdateResponse` - `id?: string` Routing rule identifier. - `actions?: Array` List actions for the catch-all routing rule. - `type: "drop" | "forward" | "worker"` Type of action for catch-all rule. - `"drop"` - `"forward"` - `"worker"` - `value?: Array` - `enabled?: true | false` Routing rule status. - `true` - `false` - `matchers?: Array` List of matchers for the catch-all routing rule. - `type: "all"` Type of matcher. Default is 'all'. - `"all"` - `name?: string` Routing rule name. - `tag?: string` Routing rule tag. (Deprecated, replaced by routing rule identifier)