Create routing rule
client.emailRouting.rules.create(RuleCreateParams { zone_id, actions, matchers, 3 more } params, RequestOptionsoptions?): EmailRoutingRule { id, actions, enabled, 4 more }
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).
Security
API Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
Example:
The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
Example:
Accepted Permissions (at least one required)
Create routing rule
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);{
"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"
}
}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,
"tag": "a7e6fb77503c41d8a7f3113c6918f10c"
}
}