I am trying to disable an origin in a pool via API. When I run the following API command it is removing all origins in the pool, not just the single one I specified. What am I missing?
curl --request PATCH --url https://api.cloudflare.com/client/v4/accounts/account_ID/load_balancers/pools/pool_identifier
-H “Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXX”
–header ‘Content-Type: application/json’
–header 'X-Auth-Email: ’
–data ‘{
“origins”: [
{
“name”: “origin-name”,
“enabled”: false
}
]
}’
You probably figured it out already but in case it helps someone else, here is an explanation for what you observe.
What you are doing here is telling the server: for this pool id, here are the origins and here is their configuration. You are giving a single origin so, quite naturally; you are setting a single origin in the pool. If you want to change the state of one of the origins in the pool, you need to set the state of all origins: one would be disabled and the others would be enabled.
In practice, the pattern you need to follow is:
- GET /pool_id
for pool in origin['pools']:
if pool['name'] == 'ORIGIN_YOU_WANT_TO_CHANGE':
pool['enabled'] = false
- PATCH /pool_id with the body = {‘origins’: origins}