Access token works in Postman but not in Azure Function

Luigi Marangio 45 Reputation points
2023-04-13T11:27:47.5066667+00:00

Hello community, I need your help to understand better what is going on here.

Situation - desired result I developed, in python, an Azure function that:

  • is triggered by a POST request
  • use the package "requests" to get an access token (for service principal) for the PowerBI REST API use this access token to send a Post request to PowerBI

Postman If I run the exact same requests in Postman, I am able to

  • retrieve the access token
  • use this access token to send my POST request Everything works fine.

Azure Function

  • the token is retrieved correctly
  • the POST request to the PowerBI API fails with a 403
  • If I copy and paste the access token retrieved by the script, and I used it in Postman, I also obtain a 403
  • If I retrieve an access token with Postman, and I use it in the script, everything works fine.

Run/test section of the Azure function show me the following:

Test/Run result

Looks like I haven't configured properly the network access of my azure function. Is there someone with experience in this field that can troubleshoot this error and explain what is going on? I did not set up the network infrastructure, so please, be as clear as possible:) Thanks! Luigi

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,932 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Luigi Marangio 45 Reputation points
    2023-04-14T10:41:11.5933333+00:00

    This was the problem: in the Azure function I was requesting the token againstthis endpoint: https://login.microsoftonline.com/{{tenant_id}}/oauth2/token Meanwhile in Postman I was using: https://login.microsoftonline.com/{{tenant_id}}/oauth2/v2.0/token which actually works.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.