Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi there fellow users of Power Bi,
I am trying to obtain some data using an API.
I have managed to get the authentication token and managed to obtain some data, but only the first 100 items.
So now I am trying to loop through all the "pages" using count and an offset.
However I get the following error:
2 arguments were passed to a function which expects 1.
The below is my code, hopefully you can help me out
let // Get authorization token Kilde = Web.Contents("https://api.XXXXXXXXX.dk/oauth2/token", [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(Uri.BuildQueryString([grant_type="password", client_id="XXXXXXXXXXXXXXXXX", client_secret="XXXXXXXXXXXXXX", email="xxxxxxx@yyyyyyyyy.com", password="XXXXXXXXXXXXX"]))]), KildeTekst = Text.FromBinary(Kilde), KildeSegmenter = Splitter.SplitTextByDelimiter("&")(KildeTekst), KildeKvps = List.Transform( KildeSegmenter, (value) => { List.First((Splitter.SplitTextByDelimiter("=")(value))), List.Last((Splitter.SplitTextByDelimiter("=")(value))) } ), KildeKvpTabel = Table.FromList(KildeSegmenter, Splitter.SplitTextByDelimiter("=")), #"Filtrerede rækker" = Table.SelectColumns(Table.SelectRows(KildeKvpTabel, each [Column1] = "access_token"), {"Column2"}), Token = Text.From(List.First(Table.SelectColumns(Table.SelectRows(KildeKvpTabel, each [Column1] = "access_token"), {"Column2"})[Column2])), EntitiesPerPage = 100, BaseUrl = "https://api.xxxxxxxxxxx.dk/v1/organizations/XXXX/vouchers", GetJson = (Url) => let Options = [Headers =[#"Authorization"="Bearer " & Token]], RawData = Web.Contents(Url, Options), Json = Json.Document(RawData,1252) in Json, GetEntityCount = () => let Url = BaseUrl & "?count=10", Options = [Headers =[#"Authorization"="Bearer " & Token]], Json = Web.Contents(Url, Options), #"Derp" = Json.Document(Json,1252), Count = Record.Field(#"Derp"[meta],"count") in Count, GetPage = (Index) => let Options = [Headers =[#"Authorization"="Bearer " & Token]], Skip = "&offset=" & Text.From(Index * EntitiesPerPage), Top = "?count=" & Text.From(EntitiesPerPage), Url = BaseUrl & Top & Skip, Json = GetJson(Url, Options), Value = Json[#"value"] in Value, EntityCount = List.Max({ EntitiesPerPage, GetEntityCount() }), PageCount = Number.RoundUp(EntityCount / EntitiesPerPage), PageIndices = { 0 .. PageCount - 1 }, Pages = List.Transform(PageIndices, each GetPage(_)), Entities = List.Union(Pages), Table = Table.FromList(Entities, Splitter.SplitByNothing(), null, null, ExtraValues.Error) in Table
I am pretty sure it's:
Pages = List.Transform(PageIndices, each GetPage(_)),
Which is causing the issue.
If I take a look at GetPage = (Index) =>
I noticed in Postman it's returning me a data and meta tag:
I tried changing the folowing line
Value = Json[#"value"]
with
Value = Json[data][#"value"]
But sadly without luck.
I really hope someone can help me, since I am pulling my hair out over this issue :S
Feel free to add me on skype: Futurelinkhev or hev@futurelink.dk if needed be
Best regards
In the step that has the error:
Add a new custom step: try PreviousStep (where PreviousStep is your previous step)
Click through the record to find the arguments passed in, which can help in identifying the issue.
You may also be able to click though to the function, and if it has documentation, it may give you a good idea where it is.