March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi Community,
I am taking data from Hubspot Private app API, I am using below M-code to get all the data, But its giving some syntax error(Token Error).
API is calling next page in this format :
" "paging": { "next": { "after": "5852", "link": "https://api.hubapi.com/crm/v3/objects/CONTACT/?limit=100&after=5852""
I written M-code to get data from this API in above format :
"
let
// Define the base URL
baseUrl = "https://api.hubapi.com/crm/v3/objects/CONTACT/?limit=100&after=",
afterValue = "5852", // Replace this with your initial "after" value
maxPages = 10, // Set the maximum number of pages to retrieve
// Initialize variables to store the results
allPages = {},
pageNumber = 1,
// Function to get a page of data
getPage = (after) =>
let
// Construct the URL for the page
pageUrl = baseUrl & after,
// Make the HTTP request to the page URL
pageContent = Json.Document(Web.Contents(pageUrl)),
// Extract the "paging" information from the page
paging = Record.FieldOrDefault(pageContent, "paging", null),
// Extract the "next" link from the paging information
nextLink = Record.FieldOrDefault(paging, "next", null)
in
if nextLink <> null then
[Data = pageContent, NextLink = Text.BetweenDelimiters(nextLink, "after=", "&")]
else
[Data = pageContent, NextLink = null],
// Function to retrieve all pages of data
retrieveAllPages = () =>
let
nextLink = afterValue,
currentData = null
in
while nextLink <> null and pageNumber <= maxPages do
let
pageResult = getPage(nextLink),
pageData = pageResult[Data],
nextLink = pageResult[NextLink]
in
if currentData = null then
currentData = pageData
else
currentData = Table.Combine({currentData, pageData}),
pageNumber = pageNumber + 1
in
currentData
in
retrieveAllPages()
"
I am getting Error in above bold code, Giving Token error.
Help is appriciated, Thanks in Advance!
Read about Headers, RelativePath and Query options for Web.Contents - PowerQuery M | Microsoft Learn
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.