What specific changes need to be made to the below code in order to successfully filter the list of Agent Pools by the properties name
and isHosted
using the Python requests module and the Azure DevOps Services REST API endpoint documented at this link?
Only 1 agent pool should be returned when the list is filtered by {name=Default,isHosted=false}
as shown below, but the problem is that the code below is returning ALL agent pools including those with different names and those that are Hosted.
import requests
import os
import base64
import json
personal_access_token = ":"+os.environ["AZ_PERSONAL_ACCESS_TOKEN"]
headers = {}
headers['Content-type'] = "application/json"
headers['Authorization'] = b'Basic ' + base64.b64encode(personal_access_token.encode('utf-8'))
#Get a list of agent pools.
instance = "dev.azure.com/MyOrganization"
propVals = "{name=Default,isHosted=false}"
api_version = "5.1"
url = ("https://%s/_apis/distributedtask/pools?properties=%s?api-version=%s" % (instance, propVals, api_version))
r = requests.get(url, headers=headers)
print("r.status_code is: ", r.status_code)
print("r.json() is: ", r.json())
Note there seems to be very little documentation of how to use Python to integrate with the Azure DevOps Services API. Also, note we are using Python 3.7.6.