iControl REST API Pool Member disable
Hello Everyone,
Iam working on an script to disable the pool members but seems we are getting issues, I tried multiple types but still its not working. Could someone review the below and quote me if Iam missing anything?
From Curl:
>curl -sku admin:pass -H "Content-Type: application/json" -X PATCH https://f5lab1.com/mgmt/tm/ltm/pool/pool_1/members/~Common~10.170.xx.xx:21 -d '{"session":"user-disabled", "state":"user-down"}'
Error: {"code":400,"message":"Found invalid JSON body in the request.","errorStack":[],"apiError":1}
# Function to disable a member in the pool ( Function using Py)
def disable_member(pool_name, member_name):
url = f'https://{F5_HOST}/mgmt/tm/ltm/pool/{pool_name}/members/~Common~{member_name}'
auth = (F5_USER, F5_PASSWORD)
data = { "session": "user-disabled" }
try:
response = requests.patch(url, auth=auth, json=data, verify=False)
return response.status_code == 200
except Exception as e:
print(f"Error disabling member: {e}")
return False
Error: 400 BAD REQUEST
also FYI...if you get a working postman sample, you can click the </> icon and find samples in a lot of tools/languages of that specific query.
And the python sample they shared from my working postman PATCH is:
import requests import json url = "https://ltm15/mgmt/tm/ltm/pool/~Common~nginx-pool/members/~Common~172.16.102.5:80" payload = json.dumps({ "session": "user-disabled", "state": "user-down" }) headers = { 'Content-Type': 'application/json', 'Authorization': 'Basic notsofastmyfriends', 'Cookie': 'BIGIPAuthCookie=supersecretpassphrasehere; BIGIPAuthUsernameCookie=admin' } response = requests.request("PATCH", url, headers=headers, data=payload) print(response.text)