Forum Discussion

Shamatix's avatar
Shamatix
Post Partisan
6 years ago

2 arguments were passed to a function which expects 1

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="[email protected]", 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:

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 [email protected] if needed be 🙂


Best regards

1 Reply

  • v-evelk's avatar
    v-evelk
    Microsoft Employee

    Hi,

     

    Unfortunately, Power BI API is out of my expertise so, it's better to ask the question in more relevant thread as this one.

     

    Kind Regards,

     

    Evgenii Elkin,
    Software Engineer
    Microsoft Power BI Custom Visuals
    [email protected]