-1

I'm trying to access the quota list/read api from a python runbook in an automation account - but how do I authenticate it?

I'm reading. I need to pass a bearer auth token in the header but the tutorials I find are all done via Postman which doesn't make sense since this is an internally ran script.

API: https://learn.microsoft.com/en-us/rest/api/reserved-vm-instances/quota/list?tabs=HTTP

I found this in the documentation, but it looks like this is for an externally ran python script? https://learn.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual-python-3

Any help here would be much appreciated.

Lav Mehta
  • 92
  • 1
  • 2
  • 13
H14
  • 15
  • 5
  • No, it's not an "internally run script". It's a script that tries to call authenticated services. To those services, it's just another external script. It *must* provide its credentials, even if those are the currently executing account. After all, there will be dozens if not hundreds of accounts and services in any Azure deployment. Nothing says that the automation account can connect to all services in a company. The article you linked to shows how to connect using the automation credentials. You could have used other credentials – Panagiotis Kanavos Aug 09 '22 at 16:21

1 Answers1

0

Here is a basic example of passing headers in a python api call. You can add the headers needed in the headers variable here to make a successful api call.

Here is the documentation on the python requests module.

import requests

# Make an API call and store the response
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
headers = {'Accept': 'application/vnd.github.v3+json'}
r = requests.get(url, headers=headers)
print(f'Status Code: {r.status_code}')

# Store the response as a variable
response_dict = r.json()
print(f"Total repositories: {response_dict['total_count']}")