Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

Rest API to disable virtual server

RahulG
Altocumulus
Altocumulus

Hi, I am trying to create a python script to disable virtual server using REST API. Could you please help me in resolving the error:

REST API: virtual_disable = requests.put("https://device/mgmt/tm/ltm/virtual/test", auth=("username","password"), data = {"disabled":True}, headers = {"Content-Type":"application/json"}, verify=False).json()

Error: {'code': 400, 'message': 'Found invalid JSON body in the request.', 'errorStack': [], 'apiError': 1}

 

1 ACCEPTED SOLUTION

jaellis
Nimbostratus
Nimbostratus

I recommend using patch instead of put. See below:

url = 'https://device/mgmt/tm/ltm/virtual/test'
data = {'disabled':True}
r=requests.patch(url, json = data, auth=("username", "password"), verify=False)
if r.status_code >= 400:
print('\tError Code: ' + str(r.status_code))
else:
print("Disabled VIP")

View solution in original post

5 REPLIES 5

Hello RahulG, 

I recommend you to send a GET request before your PUT request to check how the structure of the JSON is.

Here is an example of how to disable pool members. You can use it as a template:

https://support.f5.com/csp/article/K43713440

 

Regards,
Dario.

Hi, thanks for your reply.

I tried the GET request and the strucutre of the JSON file is similur to my REST API posted in the above query.

However I tried the below API Call but still getting same JSON error message.

virtual_disable = requests.put("https://device/mgmt/tm/ltm/virtual/test", auth=("username","password"), data = {"state": "user-down", "session": "user-enabled"}, headers = {"Content-Type":"application/json"}, verify=False).json()

jaellis
Nimbostratus
Nimbostratus

I recommend using patch instead of put. See below:

url = 'https://device/mgmt/tm/ltm/virtual/test'
data = {'disabled':True}
r=requests.patch(url, json = data, auth=("username", "password"), verify=False)
if r.status_code >= 400:
print('\tError Code: ' + str(r.status_code))
else:
print("Disabled VIP")

RahulG
Altocumulus
Altocumulus

Thanks it worked 🙂

You're welcome!!