Документация API: https://learn.microsoft.com/en-us/rest/ ... nsumption- 01.05.2023
Код: Выделить всё
import requests
# Define your Azure AD and API parameters
tenant_id = 'xxx'
client_id = 'yyy'
client_secret = 'zzz'
subscriptionId = 'www'
resource = 'https://management.azure.com/'
billingPeriodName = "202407"
# OAuth2 endpoint for token retrieval
token_url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token'
# Request headers and body for token retrieval
token_data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'scope': 'https://management.azure.com/.default'
}
# Get the access token
response = requests.post(token_url, data=token_data)
response.raise_for_status()
access_token = response.json().get('access_token')
# Endpoint to retrieve the current retail prices
retail_prices_url = f'https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/pricesheets/default?api-version=2023-05-01'
# Request headers for the API call
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
# Get the current retail prices
response = requests.get(retail_prices_url, headers=headers)
response.raise_for_status()
retail_prices_data = response.json()
response.raise_for_status() # Raise an error for bad status codes
print(token_data)
print(pricesheet_data)
Я попробовал изменить конечные точки API, дважды проверил активацию подписки, разрешил доступ к API и назначил роль созданной службе приложения. Дважды проверенные идентификаторы арендатора, клиента и т. д....
Подробнее здесь: https://stackoverflow.com/questions/787 ... -404-error