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:

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

1 REPLY 1
v-evelk
Employee
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
pbicvsupport@microsoft.com

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