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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Syndicate_Admin
Administrator
Administrator

Datos paginados sin total de páginas

Hola

He estado tratando de obtener datos dinámicos de una API sin ningún parámetro TotalPages conocido. Hay un parámetro num_pages y otro has_more ; Si has_more es 1, hay más páginas. Por lo tanto, necesito seguir obteniendo páginas hasta que has_more = 0.

He estado probando variaciones de esto:

let
    apiKey = "{my_key}",
    fnGetPage = (pageNum as number) =>
    let
        Source = Json.Document(Web.Contents("https://}myapi}", [
            Headers = [
                #"ApiKey" = apiKey
            ],
            Query = [
                num_page = pageNum
            ]
        ])),
        Data = Source[data] 
    in
        Data,

    firstPage = Json.Document(Web.Contents("https://{myapi}", [
        Headers = [
            #"ApiKey" = apiKey
        ],
        Query = [
            num_page = 1
        ]
    ])),

    hasMore = firstPage[has_more], 

    pageList = List.Generate(
        () => 1,
        each hasMore,
        each _ + 1,
        each (pageNum as number) => 
            let
                pageData = Json.Document(Web.Contents("https://{myapi}", [
                    Headers = [
                        #"ApiKey" = apiKey
                    ],
                    Query = [
                        num_page = pageNum
                    ]
                ])),
                hasMore = pageData[has_more]
            in
                hasMore
    ),

    pageNumbers = List.Transform(pageList, each { _ }), numbers
    allPages = List.Transform(pageNumbers, each fnGetPage(_)),
    combinedTable = Table.Combine(allPages)
in
    combinedTable

pero parece incorrecto y devuelve un error sobre el tipo que no puede convertir el número en texto.

Creo que lo estoy haciendo de la manera equivocada. ¿Es obvio que hay una forma más fácil de hacer esto?


2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Hola @djs1984,

¿Puedes probar este enfoque actualizado?

let
    apiKey = "{my_key}",
    baseUrl = "https://{myapi}",

    fnGetPage = (pageNum as number) =>
    let
        Source = Json.Document(Web.Contents(baseUrl, [
            Headers = [#"ApiKey" = apiKey],
            Query = [num_page = Text.From(pageNum)]
        ])),
        Data = Source[data],
        HasMore = Source[has_more]
    in
        [Data = Data, HasMore = HasMore],

    AllPages = List.Generate(
        () => [Page = 1, HasMore = true, Result = fnGetPage(1)],
        each [HasMore],
        each [Page = [Page] + 1, Result = fnGetPage([Page]), HasMore = [Result][HasMore]],
        each [Result][Data]
    ),

    CombinedTable = Table.Combine(List.Transform(AllPages, Table.FromList(_, Splitter.SplitByNothing(), {"Column1"})))
in
    CombinedTable

Hola

Gracias por responder. Desafortunadamente, recibo un error con eso:

djs1984_0-1733851496716.png

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors