Forum Discussion
sherodkeen
3 years agoFrequent Visitor
Bearer Token Expires before GET Request Completes
I have a couple of functions and a query that converts some data from an api to a table using power query. I am able to successfully get data for most endpoints in the API, but there are a few endpoi...
sherodkeen
3 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]
sherodkeen
3 years agoFrequent Visitor
v-yalanwu-msft Do you have any further ideas for help?