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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Pikislavi
New Member

API Pagination based on a field in the previous json

Hi All,

I hope someone can help me with this issue Im facing...

Im extracting a json from an url with the first record_id. It retreives json with limit of 1000 records.

That json contains the min_record and max_record.

The max record has to be used for the next call as the record_id.

 

So, lets say the first call is: 

https://xxxxxxxxx&min_ticket_id=1

the json will return:

min_record=1

max_record=1000

Then I have to run:

https://xxxxxxxxx&min_ticket_id=1000

the json will return:

min_record=1001

max_record=2000

Then I have to run:

https://xxxxxxxxx&min_ticket_id=2000

... and so on....

 

here is the code Im using:

I dont know why in the loop, it doesnt send the variable (url, [res][Next])) to the FnGetOnePage function. 

 

let
ticket_id = "1",
iterations = 20,
url = "https://xxxxxxx&min_ticket_id=" ,
data = null,
next = "",
res= null,

 

FnGetOnePage =
(url,next_ticket) as record =>

let
Source = Json.Document(Web.Contents(url & next_ticket )),
data = try Source[meta] otherwise null,
next = try Source[meta][max_ticket_id] otherwise null,
res = [Data=data, Next=next]

in
res,

GeneratedList =
List.Generate(
()=>[i=0, res = FnGetOnePage(url ,ticket_id)],
each [i]<iterations and [res][Data]<>null,
each [i=[i]+1, res = FnGetOnePage(url, [res][Next])] ,
each [res][Data]),
#"Converted to Table" = Table.FromList(GeneratedList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"max_ticket_id", "min_ticket_id", "count", "order"}, {"max_ticket_id", "min_ticket_id", "count", "order"})
in
#"Expanded Column1"

 

  THanks!

1 ACCEPTED SOLUTION
ManuelBolz
Responsive Resident
Responsive Resident

Hello @Pikislavi,

If my post helped you, please give me a 👍kudos and mark this post with Accept as Solution.

It's difficult to test or verify but I think the bug should be fixed here.

let
    ticket_id = "1",
    iterations = 20,
    url = "https://xxxxxxx&min_ticket_id=",
    data = null,
    next = "",
    res= null,

    FnGetOnePage = (url as text, next_ticket as text) as record =>
    let
        Source = Json.Document(Web.Contents(url & next_ticket)),
        data = try Source[meta] otherwise null,
        next = try Text.From(Source[meta][max_ticket_id]) otherwise null,
        res = [Data=data, Next=next]
    in
        res,

    GeneratedList = 
    List.Generate(
        ()=>[i=0, res=FnGetOnePage(url, ticket_id)],
        each [i]<iterations and [res][Data] <> null,
        each [i=[i]+1, res=FnGetOnePage(url, [res][Next])],
        each [res][Data]
    ),

    ToTable = Table.FromList(GeneratedList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Expand = Table.ExpandRecordColumn(ToTable, "Column1", {"max_ticket_id", "min_ticket_id", "count", "order"}, {"max_ticket_id", "min_ticket_id", "count", "order"})
in
    Expand


Best regards from Germany
Manuel Bolz


🟦Follow me on LinkedIn
🟨How to Get Your Question Answered Quickly
🟩Fabric Community Conference
🟪My Solutions on Github

View solution in original post

2 REPLIES 2
ManuelBolz
Responsive Resident
Responsive Resident

Hello @Pikislavi,

If my post helped you, please give me a 👍kudos and mark this post with Accept as Solution.

It's difficult to test or verify but I think the bug should be fixed here.

let
    ticket_id = "1",
    iterations = 20,
    url = "https://xxxxxxx&min_ticket_id=",
    data = null,
    next = "",
    res= null,

    FnGetOnePage = (url as text, next_ticket as text) as record =>
    let
        Source = Json.Document(Web.Contents(url & next_ticket)),
        data = try Source[meta] otherwise null,
        next = try Text.From(Source[meta][max_ticket_id]) otherwise null,
        res = [Data=data, Next=next]
    in
        res,

    GeneratedList = 
    List.Generate(
        ()=>[i=0, res=FnGetOnePage(url, ticket_id)],
        each [i]<iterations and [res][Data] <> null,
        each [i=[i]+1, res=FnGetOnePage(url, [res][Next])],
        each [res][Data]
    ),

    ToTable = Table.FromList(GeneratedList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Expand = Table.ExpandRecordColumn(ToTable, "Column1", {"max_ticket_id", "min_ticket_id", "count", "order"}, {"max_ticket_id", "min_ticket_id", "count", "order"})
in
    Expand


Best regards from Germany
Manuel Bolz


🟦Follow me on LinkedIn
🟨How to Get Your Question Answered Quickly
🟩Fabric Community Conference
🟪My Solutions on Github

Worked perfect! I lost a lot of time trying to make it work. Thanks!!

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors