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
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
Solution Sage
Solution Sage

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
Solution Sage
Solution Sage

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
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.