Forum Discussion
Need Help in M-code to get list of values
Hi Community,
Need your help!
I am writing M-code to get all the data from API, which is paginated.
like:
I created a funtion to get data from first to last like:
M-code :
let
// Define the base URL
baseUrl = "https://api.hubapi.com/crm/v3/objects/company/?limit=100&after=",
// Function to get a page of data
getPage = (after) =>
let
// Construct the URL for the page
pageUrl = baseUrl & Number.ToText(after),
// Make the HTTP request to the page URL
pageContent = Json.Document(Web.Contents(pageUrl, [
Headers = [#"Authorization" = "XXXXXXXXXXXXXXXXXXXXXXXX", #"Content-Type" = "application/json"]
])),
// Extract the "paging" information from the page
paging = Record.FieldOrDefault(pageContent, "paging", null),
// Extract the "next" link from the paging information
next = Record.FieldOrDefault(paging, "next", null)
in
next
in
getPage
I am getting the result like:
As this the value which I want to be in the URL and get list of it, I tried List.generate but its not working properly, Its giving same recurring result in every row.
Code for list :
let
Source = List.Generate(
()=>
[result = try Query4(151) otherwise null, after =151],
each [result] <> null,
each [result = try Query4([after]+1) otherwise null, after =[after]+1],
each [result]
)
in
Source
I want to get all the data from this API.
help is appreciated
Thanks!
1 Reply
- lbendlinSuper User
Please read about the Query parameter of the Web.Contents call.