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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
suchomelb
Helper I
Helper I

Expression.Error: We cannot convert a value of type Record to type List.

I have been struggling with an API issue of getting multiple pages of records in one query for some days now. Originally posted the issue in this forum, got no responses, posted it on Reddit, and got a response with a person that helped me with this adaptation of the code below. I feel I am much further along, but now I am getting the "Expression.Error: We cannot convert a value of type Record to type List." error.

 

Maybe somebody here has run into this problem and will be able to help. Thanks in advance!

 

let
GetPage = (offset) =>
let
body = "
{
""id"":""123"",
""method"":""getLeads"",
""params"":{
""where"":{
},
""limit"":""500"",
""offset"":"" & Text.From(offset) & ""
}
}",
Data = Json.Document(
Web.Contents(
"https://api.sharpspring.com/pubapi/v1.2/?accountID=##########&secretKey=##########",
[
Content = Text.ToBinary(body),
Headers=[#"Content-Type"="application/json"]
]
)
)
in
Data,


GetPages = (offset as number, accumulatedData as list) =>
let
currentPageData = GetPage(offset),
newData = List.Combine({accumulatedData, currentPageData}),
nextOffset = offset + 500
in
if List.Count(currentPageData) = 500 then @GetPages(nextOffset, newData) else newData,

Result = GetPages(0, {})
in
Result

 

2 REPLIES 2
suchomelb
Helper I
Helper I

Ok maybe this will help somebody understand better because I still can't wrap my head around what to do to fix it.

If I change the line:

currentPageData = GetPage(offset),

to 

currentPageData = Record.ToList(GetPage(offset)),

 

Then I am able to get this as "result":

suchomelb_0-1698677711049.png

I have to dive into that record to get a step "result1" to get this:

suchomelb_1-1698677870643.png

Then inside that is my potential list of 500 records. So in the code when it is looking for 500 records or not, it is only at the step where it is looking at 5 records in the picture above. Which would obviously result it it not trying to grab any more pages.. I think. I could be wrong about everything i'm thinking here. I've tried to wrap my head around how to move that part where its checking for 500 records or not after the couple drill down steps, but nothing has worked so far.

lbendlin
Super User
Super User

Most likely CurrentPageData is not a list yet. You need to navigate through it to identify the property that has the data rows.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.