cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

Json Pagination

Hi all,

 

Very new to Power BI but having some issues getting data via JSON, the first page is imported but subsequent pages are ignored. I have followed a couple of tutorials but can't seem to find the issue here:

 

https://cloudposapi.citruslime.com/swagger/ui/index

 

 

let
    Source = Json.Document(Web.Contents("https://cloudposapi.citruslime.com/api/CustomerOrder", [Headers=[Authorization="xx"]])),
    BaseUrl = "https://cloudposapi.citruslime.com/api/CustomerOrder",
    EntitiesPerPage = 1000,
 
    GetJson = (Url) =>
        let RawData = Web.Contents(Url),
            Json = Json.Document(RawData)
        in  Json,
    
    GetTotalEntities = () =>
        let Json = GetJson(BaseUrl),
            Total = Json[total]
        in  Total,

    GetPage = (Index) =>
        let Skip  = "skip=" & Text.From(Index * EntitiesPerPage),
            Url   = BaseUrl & "&" & Skip,
            Json  = GetJson(Url),
            Value = Json[data]
        in  Value,

    GetUrl = (Index) =>
        let Skip  = "skip=" & Text.From(Index * EntitiesPerPage),
            Url   = BaseUrl & "&" & Skip
        in  Url,
  
    EntityCount = List.Max({ EntitiesPerPage, GetTotalEntities() }),
    PageCount   = Number.RoundUp(EntityCount / EntitiesPerPage),
    PageIndices = { 0 .. PageCount - 1 },
   
 URLs  = List.Transform(PageIndices, each GetUrl(_)),
 Pages       = List.Transform(PageIndices, each GetPage(_)),
    Entities    = List.Union(Pages),
    
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"Uid", "ClientRef", "Closed", "DateCreated", "TypeAsString", "Type", "Comment", "CustomerID", "ShipToID", "Deposit", "Tax", "Total", "LastUpdated", "DueDate", "Taxable", "SalesRepID", "ReferenceNumber", "ShippingChargeOnOrder", "ChannelTypeAsString", "ChannelType", "CheckedIn", "CustomerName", "OrderLines"}, {"Uid", "ClientRef", "Closed", "DateCreated", "TypeAsString", "Type", "Comment", "CustomerID", "ShipToID", "Deposit", "Tax", "Total", "LastUpdated", "DueDate", "Taxable", "SalesRepID", "ReferenceNumber", "ShippingChargeOnOrder", "ChannelTypeAsString", "ChannelType", "CheckedIn", "CustomerName", "OrderLines"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Column1",{{"Total", Currency.Type}})
in
    #"Changed Type"

 

1 REPLY 1
Highlighted
Community Support
Community Support

Re: Json Pagination

Hi @mtbmat ,

I can't test this in my environment because of the authentication. You could check each step to see which step can't work. By the way, you also could @ super users for more suggestions.

Thanks for your understanding and support.
Best Regards,
Zoe Zhi

 

Helpful resources

Announcements
Super Users of the Quarter - Q2 2020

Super Users of the Quarter - Q2 2020

Who are our Super User Superstars? Who made it to the top of the leaderboards? Get the answers!

June 2020 Community Highlights

June 2020 Community Highlights

Featured community members, changes to the Community, and more! Read up on recent Power BI community news.

Community Summit North America

Community Summit North America

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

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021