Create Load Balancer
Create a new load balancer.
Security
API Token
The preferred authorization scheme for interacting with the Cloudflare API. Create a token.
API Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
Accepted Permissions (at least one required)
Body ParametersJSON
A list of pool IDs ordered by their failover priority. Pools defined here are used by default, or when region_pools are not configured for a given region.
The DNS hostname to associate with your Load Balancer. If this hostname already exists as a DNS record in Cloudflare's DNS, the Load Balancer will take precedence and the DNS record will not be used.
A mapping of country codes to a list of pool IDs (ordered by their failover priority) for the given country. Any country not explicitly defined will fall back to using the corresponding region_pool mapping if it exists else to default_pools.
Enterprise only: A mapping of Cloudflare PoP identifiers to a list of pool IDs (ordered by their failover priority) for the PoP (datacenter). Any PoPs not explicitly defined will fall back to using the corresponding country_pool, then region_pool mapping if it exists else to default_pools.
Whether the hostname should be gray clouded (false) or orange clouded (true).
A mapping of region codes to a list of pool IDs (ordered by their failover priority) for the given region. Any regions not explicitly defined will fall back to using default_pools.
Time, in seconds, until a client's session expires after being created. Once the expiry time has been reached, subsequent requests may get sent to a different origin server. The accepted ranges per session_affinity policy are: - "cookie" / "ip_cookie": The current default of 23 hours will be used unless explicitly set. The accepted range of values is between [1800, 604800]. - "header": The current default of 1800 seconds will be used unless explicitly set. The accepted range of values is between [30, 3600]. Note: With session affinity by header, sessions only expire after they haven't been used for the number of seconds specified.
Create Load Balancer
curl https://api.cloudflare.com/client/v4/zones/$ZONE_ID/load_balancers \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-d '{
"default_pools": [
"17b5962d775c646f3f9725cbc7a53df4",
"9290f38c5d07c2e2f4df57b1f61d4196",
"00920f38ce07c2e2f4df50b1f61d4194"
],
"fallback_pool": "fallback_pool",
"name": "www.example.com",
"country_pools": {
"GB": [
"abd90f38ced07c2e2f4df50b1f61d4194"
],
"US": [
"de90f38ced07c2e2f4df50b1f61d4194",
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"description": "Load Balancer for www.example.com",
"pop_pools": {
"LAX": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
],
"LHR": [
"abd90f38ced07c2e2f4df50b1f61d4194",
"f9138c5d07c2e2f4df57b1f61d4196"
],
"SJC": [
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"proxied": true,
"region_pools": {
"ENAM": [
"00920f38ce07c2e2f4df50b1f61d4194"
],
"WNAM": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
]
},
"session_affinity": "cookie",
"session_affinity_ttl": 1800,
"steering_policy": "dynamic_latency",
"ttl": 30
}'{
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"result": {
"id": "699d98642c564d2e855e9661899b7252",
"adaptive_routing": {
"failover_across_pools": true
},
"country_pools": {
"GB": [
"abd90f38ced07c2e2f4df50b1f61d4194"
],
"US": [
"de90f38ced07c2e2f4df50b1f61d4194",
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"created_on": "2014-01-01T05:20:00.12345Z",
"default_pools": [
"17b5962d775c646f3f9725cbc7a53df4",
"9290f38c5d07c2e2f4df57b1f61d4196",
"00920f38ce07c2e2f4df50b1f61d4194"
],
"description": "Load Balancer for www.example.com",
"enabled": true,
"fallback_pool": "fallback_pool",
"location_strategy": {
"mode": "resolver_ip",
"prefer_ecs": "always"
},
"modified_on": "2014-01-01T05:20:00.12345Z",
"name": "www.example.com",
"networks": [
"string"
],
"pop_pools": {
"LAX": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
],
"LHR": [
"abd90f38ced07c2e2f4df50b1f61d4194",
"f9138c5d07c2e2f4df57b1f61d4196"
],
"SJC": [
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"proxied": true,
"random_steering": {
"default_weight": 0.2,
"pool_weights": {
"9290f38c5d07c2e2f4df57b1f61d4196": 0.5,
"de90f38ced07c2e2f4df50b1f61d4194": 0.3
}
},
"region_pools": {
"ENAM": [
"00920f38ce07c2e2f4df50b1f61d4194"
],
"WNAM": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
]
},
"rules": [
{
"condition": "http.request.uri.path contains \"/testing\"",
"disabled": true,
"fixed_response": {
"content_type": "application/json",
"location": "www.example.com",
"message_body": "Testing Hello",
"status_code": 0
},
"name": "route the path /testing to testing datacenter.",
"overrides": {
"adaptive_routing": {
"failover_across_pools": true
},
"country_pools": {
"GB": [
"abd90f38ced07c2e2f4df50b1f61d4194"
],
"US": [
"de90f38ced07c2e2f4df50b1f61d4194",
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"default_pools": [
"17b5962d775c646f3f9725cbc7a53df4",
"9290f38c5d07c2e2f4df57b1f61d4196",
"00920f38ce07c2e2f4df50b1f61d4194"
],
"fallback_pool": "fallback_pool",
"location_strategy": {
"mode": "resolver_ip",
"prefer_ecs": "always"
},
"pop_pools": {
"LAX": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
],
"LHR": [
"abd90f38ced07c2e2f4df50b1f61d4194",
"f9138c5d07c2e2f4df57b1f61d4196"
],
"SJC": [
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"random_steering": {
"default_weight": 0.2,
"pool_weights": {
"9290f38c5d07c2e2f4df57b1f61d4196": 0.5,
"de90f38ced07c2e2f4df50b1f61d4194": 0.3
}
},
"region_pools": {
"ENAM": [
"00920f38ce07c2e2f4df50b1f61d4194"
],
"WNAM": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
]
},
"session_affinity": "cookie",
"session_affinity_attributes": {
"drain_duration": 100,
"headers": [
"x"
],
"require_all_headers": true,
"samesite": "Auto",
"secure": "Auto",
"zero_downtime_failover": "sticky"
},
"session_affinity_ttl": 1800,
"steering_policy": "dynamic_latency",
"ttl": 30
},
"priority": 0,
"terminates": true
}
],
"session_affinity": "cookie",
"session_affinity_attributes": {
"drain_duration": 100,
"headers": [
"x"
],
"require_all_headers": true,
"samesite": "Auto",
"secure": "Auto",
"zero_downtime_failover": "sticky"
},
"session_affinity_ttl": 1800,
"steering_policy": "dynamic_latency",
"ttl": 30,
"zone_name": "example.com"
},
"success": true
}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"
}
}
],
"result": {
"id": "699d98642c564d2e855e9661899b7252",
"adaptive_routing": {
"failover_across_pools": true
},
"country_pools": {
"GB": [
"abd90f38ced07c2e2f4df50b1f61d4194"
],
"US": [
"de90f38ced07c2e2f4df50b1f61d4194",
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"created_on": "2014-01-01T05:20:00.12345Z",
"default_pools": [
"17b5962d775c646f3f9725cbc7a53df4",
"9290f38c5d07c2e2f4df57b1f61d4196",
"00920f38ce07c2e2f4df50b1f61d4194"
],
"description": "Load Balancer for www.example.com",
"enabled": true,
"fallback_pool": "fallback_pool",
"location_strategy": {
"mode": "resolver_ip",
"prefer_ecs": "always"
},
"modified_on": "2014-01-01T05:20:00.12345Z",
"name": "www.example.com",
"networks": [
"string"
],
"pop_pools": {
"LAX": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
],
"LHR": [
"abd90f38ced07c2e2f4df50b1f61d4194",
"f9138c5d07c2e2f4df57b1f61d4196"
],
"SJC": [
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"proxied": true,
"random_steering": {
"default_weight": 0.2,
"pool_weights": {
"9290f38c5d07c2e2f4df57b1f61d4196": 0.5,
"de90f38ced07c2e2f4df50b1f61d4194": 0.3
}
},
"region_pools": {
"ENAM": [
"00920f38ce07c2e2f4df50b1f61d4194"
],
"WNAM": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
]
},
"rules": [
{
"condition": "http.request.uri.path contains \"/testing\"",
"disabled": true,
"fixed_response": {
"content_type": "application/json",
"location": "www.example.com",
"message_body": "Testing Hello",
"status_code": 0
},
"name": "route the path /testing to testing datacenter.",
"overrides": {
"adaptive_routing": {
"failover_across_pools": true
},
"country_pools": {
"GB": [
"abd90f38ced07c2e2f4df50b1f61d4194"
],
"US": [
"de90f38ced07c2e2f4df50b1f61d4194",
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"default_pools": [
"17b5962d775c646f3f9725cbc7a53df4",
"9290f38c5d07c2e2f4df57b1f61d4196",
"00920f38ce07c2e2f4df50b1f61d4194"
],
"fallback_pool": "fallback_pool",
"location_strategy": {
"mode": "resolver_ip",
"prefer_ecs": "always"
},
"pop_pools": {
"LAX": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
],
"LHR": [
"abd90f38ced07c2e2f4df50b1f61d4194",
"f9138c5d07c2e2f4df57b1f61d4196"
],
"SJC": [
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"random_steering": {
"default_weight": 0.2,
"pool_weights": {
"9290f38c5d07c2e2f4df57b1f61d4196": 0.5,
"de90f38ced07c2e2f4df50b1f61d4194": 0.3
}
},
"region_pools": {
"ENAM": [
"00920f38ce07c2e2f4df50b1f61d4194"
],
"WNAM": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
]
},
"session_affinity": "cookie",
"session_affinity_attributes": {
"drain_duration": 100,
"headers": [
"x"
],
"require_all_headers": true,
"samesite": "Auto",
"secure": "Auto",
"zero_downtime_failover": "sticky"
},
"session_affinity_ttl": 1800,
"steering_policy": "dynamic_latency",
"ttl": 30
},
"priority": 0,
"terminates": true
}
],
"session_affinity": "cookie",
"session_affinity_attributes": {
"drain_duration": 100,
"headers": [
"x"
],
"require_all_headers": true,
"samesite": "Auto",
"secure": "Auto",
"zero_downtime_failover": "sticky"
},
"session_affinity_ttl": 1800,
"steering_policy": "dynamic_latency",
"ttl": 30,
"zone_name": "example.com"
},
"success": true
}