Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Testing out PAT tokens can hit required endpoints they need to get to in Azure DevOps.
#!/usr/bin/env python
import requests
import sys
import pprint
import base64
def encode_string(token):
to_encode_string = "Basic:" + token
encoded_str = base64.b64encode(to_encode_string.encode()).decode('utf-8')
return encoded_str
def send_request(endpoint, encoded_str):
auth_header = 'Basic ' + encoded_str
r = requests.get(endpoint, headers={'Authorization' : auth_header})
result = r.json()
if result:
print("Endpoint " + endpoint + " authorization successful.")
print("Something failed sending request to endpoint " + url + ". Check your PAT token and api endpoints.")
def main():
if len(sys.argv) == 2:
token = sys.argv[1]
encoded_str = encode_string(token)
# Add your required endpoints here. Projects is here as an example.
urls = [
for url in urls:
result = send_request(url, encoded_str)
print("Something failed for endpoint " + url + ". Check the scope of the PAT token and available organisations.")
print("Usage: python " + sys.argv[0] + " RAW_PAT_TOKEN")
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment