cancel
Showing results for 
Search instead for 
Did you mean: 
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
Exciting changes

Power BI Community Changes

Check out the changes to the Power BI Community announced at Build.

May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Kudo Data Story carousel

Data Stories Gallery

Visit our Data Stories Gallery and give kudos to your favorite Data Stories.

Top Solution Authors
Top Kudoed Authors