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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MichaelvdZ
New Member

How to define a variable for dynamic refresh token for api calls

Hi guys,

 

I try to use a Rest API that uses an access token as authentication, which expires in 10 minutes. When this access token is expired, I need to get a new access token using a refresh token, that can be used once and is valid for 30 days. Each time you request a new access token, a new refresh token is returned aswell that must be used in the next refresh. Therefore, the refresh token needs to be stored somewhere, where it can both be (1) updated in the current refresh run and (2) collected to refresh the access token in the next refresh run. This is were we run into the problem as we do not know how to setup a framework in Power BI that facilitates both these options.

 

Each time we request a new access token, the response is as follows:

{

   "access_token": "xxxxxxx",

   "token_type": "bearer",

   "expires_in": "600",

   "refresh_token": "yyyyyy"

}

 

Storing both tokens in a table, seems to be the logical option here, but there is an additonal catch; it can occur that the refresh of the data takes more than 10 minutes. In which case the access_token needs to be refreshed multiple times during the same Power BI refresh run. And since the refresh_token also changes after refreshing the access_token, it cannot be stored in a parameter. 

 

The issue is almost similar to the following issue: Power-Query/Channel-Advisor-API-Connection-with-auth-key-creation

 

However our refresh_token (authentication) is not static (like a username and password), but changes after each refresh.

 

Is there any way to define a variable for the refresh_token that can be used in each different query and that can also be updated whenever you request a new access_token (even during the same refresh run)?

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Power BI has no memory and no concept of (mutable) variables. You need to treat each API call as if it were the first.

View solution in original post

2 REPLIES 2
peggysue
Advocate I
Advocate I

Hi @MichaelvdZ, instead of trying to refresh my access token, I found a really easy way to have Power BI request a new access token after my original one expired. I hope this helps!

 

See my post in this thread: https://community.fabric.microsoft.com/t5/Service/API-with-dynamic-access-token-can-t-refresh-in-Pow...

 

lbendlin
Super User
Super User

Power BI has no memory and no concept of (mutable) variables. You need to treat each API call as if it were the first.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors