Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Trouble using a dynamic token function/variable for my data query

Hello!   For a dashboard I am batching data from an API. For acces I am using a token that's only valid for 2 hours. For this reason I created a seperate query to retrieve this token. This Token q...
  • tex628's avatar
    tex628
    3 years ago

    It's slightly hard doing this blind, but how does it look if you try the code below? 

    let
      List = List.Generate( () => 0, each _ <= 80000, each _ + 2000 ),
    
      Source = Json.Document(Web.Contents("https://geolive-acc.bim.xxxx.nl/portal/sharing/rest/oauth2/token/?client_id=xxxxxx&client_secret=xxxxxxx&grant_type=client_credentials")),
      #"Converted to Table" = Table.FromRecords({#"Source"}),
      #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"access_token", type text}, {"expires_in", Int64.Type}}),
      #"access_token1" = #"Changed Type"{0}[access_token],
      Token = #"Changed Type"{0}[access_token],
      
      #"Converted to Table1" = Table.FromList(List, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
      #"Changed Type2" = Table.TransformColumnTypes(#"Converted to Table1",{{"Column1", type text}}), 
      #"Added Custom - QUERY" = Table.AddColumn(#"Changed Type2", "Custom.1", each Json.Document(Web.Contents("https://geolive-acc.bim.xxx.nl/server",
    [
      RelativePath="rest/services/Hosted/xxxxxx/FeatureServer/0/query",
      Query = [
        where="1=1",
        outFields="*",
        resultOffset=[Column1],
        token=Token,
        f="json" ]
    ]
    )))
    in 
    #"Added Custom - QUERY"