Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4066

Azure API access

$
0
0

I want to have access to the APIs of this swagger file: https://flightclaims-dev.azurewebsites.net/swagger/index.htmlBut with the following code I ran into 401 error:

from azure.identity import ClientSecretCredentialimport requests# Azure AD configurationTENANT_ID = 'xxx'CLIENT_ID = 'xxx'CLIENT_SECRET = 'xxx'# Delegated scopes required for Microsoft Graph API accessSCOPES = ['User.Read']  # Example scopes# Initialize the Azure Identity client with client secret credentialcredential = ClientSecretCredential(    tenant_id=TENANT_ID,    client_id=CLIENT_ID,    client_secret=CLIENT_SECRET)# Obtain an access token for Microsoft Graph API with delegated permissionstoken_data = credential.get_token("https://graph.microsoft.com/.default", scopes=SCOPES)access_token = token_data.tokenprint(token_data)# Microsoft Graph API endpointgraph_api_endpoint = 'https://flightclaims-dev.azurewebsites.net/api/ApplicationParameter'# Set headers with Authorization tokenheaders = {'Authorization': 'Bearer '+ access_token}try:    # Make a GET request to Microsoft Graph API endpoint with headers    response = requests.get(graph_api_endpoint, headers=headers)    # Check if the request was successful (status code 200)    if response.status_code == 200:        # Print the response data        print(response.json())    else:        # Print error message if request was not successful        print(f'\nFailed to retrieve data. Status code: {response.status_code}')        print(response.text)  # Print error response if neededexcept requests.exceptions.RequestException as e:    # Print error message if an exception occurs during the request    print(f'An error occurred: {e}')

The token that I get is correct by the way.

I probably need to change my Azure API permissions but I don't know how?


Viewing all articles
Browse latest Browse all 4066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>