cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Shamatix Post Patron
Post Patron

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="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:

Postman_odOsBHvjNX.png

 

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

2 REPLIES 2
Microsoft artemus
Microsoft

Re: 2 arguments were passed to a function which expects 1

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.

Shamatix Post Patron
Post Patron

Re: 2 arguments were passed to a function which expects 1

Hi there Artemus,

I actually managed to find the issue, but stumbled right into another one I described here
https://community.powerbi.com/t5/Desktop/We-cannot-apply-field-access-to-the-type-List/td-p/851856

Really hope you can help 🙂

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors