I am trying to get all the work items for a project in Azure DevOps.
The issue I am facing is of is authentication. How do I authenticate/login before sending this post request?
The docs show security as 0auth2
. However, I have a personal access token...what would be the correct approach? How to send an authenticated POST request that is. Do I have to register the application and get 0auth
Token etc..or PAT would suffice?
import requests
import base64
pat = 'nbq'
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii')
headers = {
'Accept': 'application/json',
'Authorization': 'Basic '+authorization
}
# response = requests.get(url="https://dev.azure.com/company/_apis/projects?api-version=5.1", headers=headers).json()
data = {
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Task'"
}
wo_it = requests.post('https://dev.azure.com/company/example_project/_apis/wit/wiql?api-version=5.1',data=data)
print(wo_it.text)