I'm trying to build a (what I thought would be) a simple script in Python to download Microsoft's Azure's rate card using the Billing API.
token_response = adal.acquire_token_with_client_credentials(
'https://login.microsoftonline.com/' + TENANT_ID,
CLIENT-ID,
CLIENT-KEY)
access_token = token_response.get('accessToken')
endpoint = "https://management.azure.com/subscriptions/[SUBSCRIPTION-ID]/providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview&$filter=OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'GBP' and Locale eq 'en-GB' and RegionInfo eq 'GB'"
headers = {"Authorization": 'Bearer ' + access_token}
out = requests.get(endpoint,headers=headers)
json_output = out.json()
print son_output
The query seems to be executing correctly. Authorisation seems to go ok, and I'm getting a 200 OK message response. But the output is empty: {u'value': []}. I've tried different OfferIDs, different $filter strings and now it's driving me mad...
I wonder if perhaps I haven't delegated suitable permissions, but I've created an Application attached to Active Directory, generated a key, and delegated permissions to Windows Azure Service Management? And if that was the problem, wouldn't I receive an error?
Happy to hear alternative ways of doing the same thing, but Python is all I really know...
Please make sure that the user account you're using to interact with the billing and usage API has access to the Azure Subscription. In your case, you're using a Service Principal
so please make sure that this user is assigned a role in the Subscription.
To assign a Service Principal
a role, you may find this link helpful: https://azure.microsoft.com/en-in/documentation/articles/resource-group-create-service-principal-portal/.
When it comes to assigning role, since this user only needs to read the data, its better to go with Reader
role so that inadvertent changes can't be made to your Azure Subscription.