Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Shamatix
Post Partisan
Post Partisan

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
artemus
Employee
Employee

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.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors