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.
Solved! Go to Solution.
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
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