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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

REST API Pagination - unable to convert to number

Hi peeps,

I'm trying to connect to an API and go through multiple pages dynamically. I've been watching this video and I'm trying to replicate it in my query but I'm a bit stuck.

https://www.youtube.com/watch?v=05yhwnuCjRw 

This is what works:

 

(nextP as text)=>
let
    nextKey = Text.Combine({"""",nextP,""""},""), //adds ""nextKey""
    url = "https://URL/runquery?configCode=ds_adminuser",
    body = "{
            ""name"":""User Data"",
            ""pageSize"":""4"",
            ""nextKey"":"&nextKey&",
               }",
    header = [  #"Authorization"="Basic base64auth",
                #"Content-Type"= "application/json"],
    Source = Json.Document(Web.Contents(
            url, 
            [Headers=header,
            Content = Text.ToBinary(body)]
            )
    ),
    data = Source[data],
in
    data

 

 Now I'm trying to convert nextP into number so I can iterate through it using List.Generate (I haven't gotten that far yet).

When I try to convert it to number it doesn't work and I'm not sure why:

 

(nextP as number)=>
let
    nextKey = Text.Combine({"""",nextP,""""},""), //adds ""nextKey""
    url = "https://URL/runquery?configCode=ds_adminuser",
    body = "{
            ""name"":""User Data"",
            ""pageSize"":""4"",
            ""nextKey"":"&Number.To.Text(nextKey)&",
               }",
    header = [  #"Authorization"="Basic base64auth",
                #"Content-Type"= "application/json"],
    Source = Json.Document(Web.Contents(
            url, 
            [Headers=header,
            Content = Text.ToBinary(body)]
            )
    ),
    data = Source[data],
in
    data

 

This is what I get:

 

An error occurred in the ‘’ query. Expression.Error: We cannot convert the value 1 to type Text.
Details:
    Value=1
    Type=[Type]

 

Thanks in advance

GT

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please look at just the body part (put body as your "in").  I think you want """ instead of """" in your Text.Combine.  Also, you probably need to wrap nextP with Number.ToText(nextP) .

 

mahoneypat_0-1636981252169.png

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Please look at just the body part (put body as your "in").  I think you want """ instead of """" in your Text.Combine.  Also, you probably need to wrap nextP with Number.ToText(nextP) .

 

mahoneypat_0-1636981252169.png

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thanks Pat,

What worked was the wrapping of nextP with Number.ToText(nextP). I thought I tried that before but it seems I didn't. 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors
Top Kudoed Authors