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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
5kancho
Frequent Visitor

Getting API refresh token for long running query

Hello. I am calling an API to get data into Power BI but am facing an issue that my authorization token expires for the API before the query completes. The JWT Token used for authentication is set to expire every 10 minutes. There is an API URL that can be called to extend the session for the existing token but I am new to M so I do not know how to track the execution time of the query and call that URL before the 10 minute mark is reached.

Would appreaciate any help and am here if more details are required to provide an answer.

1 ACCEPTED SOLUTION
MAwwad
Super User
Super User

You could track the start time of the query and then compare it to the current time. If the difference between the start time and current time is greater than 10 minutes, you could make a call to the API URL to extend the session with a new token before continuing with the query.

Here's some sample code in M language to accomplish this:

let startTime = DateTime.LocalNow(), result = #"Your data source query", currentTime = DateTime.LocalNow(), timeDiff = currentTime - startTime, renewToken = if timeDiff > #duration(0, 10, 0, 0) then // code to renew token here else null in result

View solution in original post

1 REPLY 1
MAwwad
Super User
Super User

You could track the start time of the query and then compare it to the current time. If the difference between the start time and current time is greater than 10 minutes, you could make a call to the API URL to extend the session with a new token before continuing with the query.

Here's some sample code in M language to accomplish this:

let startTime = DateTime.LocalNow(), result = #"Your data source query", currentTime = DateTime.LocalNow(), timeDiff = currentTime - startTime, renewToken = if timeDiff > #duration(0, 10, 0, 0) then // code to renew token here else null in result

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors