Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
JECp
Regular Visitor

Can't get API token from Azure machines...

 

I have a program that uses the Power BI API and has been running just fine for years. We recently moved some machines from on-prem to Azure VMs and suddenly this program no longer works. The error occurs when I run:

 

Using tsk As Tasks.Task(Of AuthenticationResult) = ctxt.AcquireTokenAsync("https://analysis.windows.net/powerbi/api", sClientID, cred)
                tsk.Wait()
End Using

 

The StackTrace is:

JECp_0-1717624378867.png

Unfortunately, the error message is an incredibly helpful "One or more errors occurred".

 

At first, we thought it was a firewall issue, but we can access sites using https, so we know Port 443 is open and working, and the documentation says that the Power BI API only uses 443.

 

Does anyone have any ideas on what could possibly cause this?

 

2 REPLIES 2
Anonymous
Not applicable

Hi @JECp ,

It sounds like there may be an issue with the authentication process when trying to acquire the API token. The possible solution could be to check if the Azure VMs have the sufficient permissions to access the Power BI API. You may also want to check if the client ID and credentials being used are still valid and have not expired or been revoked.

How to do the authentication to run Power Bi Rest Api in an Azure Function (PowerShell)? - Stack Ove...

How to generate Access Token for Azure with grant type password? PowerBI REST API - Stack Overflow

 

Tutorial: Grant a user access to Azure resources using the Azure portal - Azure RBAC | Microsoft Lea...

Azure Permissions 101: How to manage Azure access effectively 

Best Regards

We looked into firewall and DNS issues, but everything was clear on that front. I was able to get more info about the error though, and it shows this:

 

JECp_1-1717695743559.png

 

I don't understand why I'm getting this, as this is the same App Reg, same user being used for authentication, same network. It's just that the machines I run this from (when it fails) are all Azure VMs. Any on-prem machine works just fine.

 

Is it seeing Azure VMs as being at a different "location"? If so, how do I address this? I need this code to run from both locations.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.