7

So, from what I see from most sources, they say if youre trying to make a python program call azure devops api calls, it uses a python import statement such as :

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
...

Is there any way to use requests or other built in import statements so I dont have to install these devops specific modules? I'm coding in putty so I dont have a way to install these modules.

If anyone's got any solutions or ideas I'd be happy to hear it!

1 Answer 1

21

Surely, it is supported to use requests to call Azure DevOps REST API

Firstly, you need to create a personal access token (PAT)

Then you can use the PAT to create the basic auth header, and make the request:

import requests
import base64

pat = 'tcd******************************tnq'
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii')

headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic '+authorization
}

response = requests.get(
    url="https://dev.azure.com/jack0503/_apis/projects?api-version=5.1", headers=headers)
print(response.text)

Sign up to request clarification or add additional context in comments.

4 Comments

Awesome. I'm sure that was a surface level question but it helps wrap my head around things. Do you know if theres anything else I would need to do different regarding the API in terms of searching for PBIs and searching for terms in the titles, or should that be fairly straightforward?
Do you refer to Power BI? Actually, Microsoft officially provides documentation for Azure DevOps REST API and Power BI REST API. While the the authentication problem issolved, calling the API is very simple.
Is the PAT mandatory? Can I use login and password?
@AstraSerg for basic authentication with login and password you can use requests.get(url="http://dev.azure...", auth=HTTPBasicAuth(username, p)). There's a fine example here clouddev.engineering/azure-devops-rest-api-with-python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.