Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon'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.
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?
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:
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.