0

I would like to connect VSTS(Azure) through python code using my personal token. The main reason for this is to query the vsts and get the query results by python code

I am trying with different code using Spyder(Python 3.6) but its not working.

Please share me the sample python code to fetch the query results from VSTS.

Shyam
  • 57
  • 1
  • 5

1 Answers1

1

How to connect VSTS through Python by VSTS personal token to query and fetch the query results

To connect Azure Devops through Python by VSTS personal token, you can use following connection code:

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

# Fill in with your personal access token and org URL
personal_access_token = 'YOURPAT'
organization_url = 'https://dev.azure.com/YOURORG'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

Check the document Azure DevOps Python API for some more details.

And if want to uery and fetch the query results with Python REST API, you can refer to this thread.

Besides, since you do not share the detailed info about your code you tried and what not worked, I could not give you an accurate answer, but MS provide some samples how to use the Python REST API:

Python samples for Azure DevOps

Hope this helps.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Thanks a lot for your support. I was using following code to connect azure.from vsts.vss_connection import VssConnection from msrest.authentication import BasicAuthentication import pprint token = 'MyToken' team_instance = 'https://myorg.com' credentials = BasicAuthentication('',token) connection = VssConnection(base_url=team_instance, creds=credentials) core_client = connection.get_client('vsts.core.v4_0.core_client.CoreClient') team_projects = core_client.get_projects() for project in team_projects: pprint.pprint(project._dict_) – Shyam Aug 30 '19 at 09:43
  • @Shyam, So what is your problem now? You could update your question with python scripts you are using and the error log. – Leo Liu Sep 03 '19 at 08:51
  • Thanks @Leo Liu,The above answer was very helpful for me. I am able achieve it – Shyam Sep 05 '19 at 09:56