Forum Discussion
Bearer Token Expires before GET Request Completes
Unfortunatly, none of the links you provided help in this specific case. Is there anything I can modify in my code to ensure that it is using a new token for each api call?
I'm attempting now to try and put the GetToken() function as a parameter in the table query in the List.Generation part of the function. Hoping this will retrigger the try for a token, which should be new each time the query is ran.
- sherodkeen3 years agoFrequent Visitor
I'm still struggling with this one. Looks like everytime the loop runs in the List.Generate(), the call to my custom GetToken() function is just regiving the loop the same token. I was hoping to get a new token on each loop so that I wouldn't run into the 30 min expiration that each token has.
let Source = List.Generate(()=> [Result = fApi(0,endpoint,ext,accesstoken), offset=0, endpoint="staffs", ext="ed-fi", accesstoken = GetToken()], each not (Table.IsEmpty([Result])), each [Result = fApi([offset], [endpoint], [ext], [accesstoken]), offset=[offset]+Number.FromText(LimitOffset), endpoint=[endpoint], ext=[ext], accesstoken = GetToken()], each [accesstoken]) in Source(Offset as number, endpoint as text, ext as text, accesstoken as text)=> let data = Json.Document(Web.Contents(baseUrl, [ Headers = [#"Authorization"="Bearer "&accesstoken,#"Content-Type"="application/json"], RelativePath=relativePath&"/"&ext&"/"&endpoint, Query = [#"limit"=LimitOffset,#"offset"=Number.ToText(Offset)] ] ) ), #"Converted to Table" = Table.FromList(data, Splitter.SplitByNothing(), null, null, ExtraValues.Error) in #"Converted to Table"() => let token_url = tokenUrl, body = "Client_id="&clientKey&"&Client_secret="&clientSecret&"&Grant_type="&grantType, Source = Json.Document(Web.Contents(token_url, [ Headers = [#"Content-Type"="application/x-www-form-urlencoded"], Content = Text.ToBinary(body) ] ) ) in Source[access_token]- sherodkeen3 years agoFrequent Visitor
v-yalanwu-msft Do you have any further ideas for help?