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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
KEMKEM
Regular Visitor

How to use the Power Bi Rest Api without the refreshtoken?

I have a powershell script which is using the Power Bi Rest Api. For the authentication they use some strange solution. They capture the refresh token from the browser and save it in a txt file. Than there is some algoritme which gets a token by the refresh token in the txt file. I dont like this ugly solution.

 

How can I use the Power Bi Rest Api without this ugly refreshtoken solution? I would like to run this script in an Azure function.

 

I would for example run this rest api:

 

 

https://api.powerbi.com/v1.0/myorg/groups/{groupId}/dataflows/{dataflowId}/transactions

 

 

5 REPLIES 5
lbendlin
Super User
Super User

Ask for a bog standard auth token each time before your API call.  You need to have an app registered with the required scope, client secret etc.

I dont understand what you mean. Please share some documentation or code snipped.

The code I posted will allow you to receive an auth token without any interaction, as often as needed  (I call it before each REST API call). No need for a refresh token. Efficiency be damned.

Hi @lbendlin  Do you have more info? Maybe some link to a tutorial or blog? Or some code snipped?

for example

 

# Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD
function GetAuthToken
{
    if(-not (Get-Module AzureRm.Profile)) {
        Import-Module AzureRm.Profile
    }
    $clientId = "xxx"
    $redirectUri = "urn:ietf:wg:oauth:2.0:oob"
    $resourceAppIdURI = "https://analysis.windows.net/powerbi/api"
    $authority = "https://login.microsoftonline.com/common/oauth2/authorize";
    $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
    $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto")
    return $authResult
}

# Get the auth token from AAD
$token = GetAuthToken

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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