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
loginerror
Frequent Visitor

Help adjusting List.Generate REST function around error "Unable to do a refresh on Web.contents()"

Hi,

I have seen multiple posts on how to achieve it, but I have trouble adapting my custom REST API function.

 

Please see below my source function:

 

(queryID) => let
        resultCount = 1000,
        otherNameForPage = 0,
        URL = "https://baseURL/admin/plugins/explorer/queries/" & Number.ToText(queryID) & "/run",

        GetPage = (otherNameForPage) =>
            let
                content1 = "params={""page"":""" & Number.ToText(otherNameForPage) & """}",
                RawData = Json.Document(Web.Contents(
                    URL,
                    [
                        Headers = [ 
                        #"api-username"="myUserName",
                        #"api-key"="myAPIKey",
                        #"Content-Type" = "application/x-www-form-urlencoded"],
                        Content = Text.ToBinary(content1)
                    ]
                    
                ) ),
                resultCount = RawData[result_count]
            in
                if RawData[result_count] = 0 then null else RawData,
            Pages = List.Generate(
                () => [i = 0, RawData = GetPage(i)],
                each [RawData] <> null,
                each [i=[i]+1, RawData = GetPage(i)],
                //each Record.ToTable([RawData])),
                each Table.Combine(let raw = [RawData] in List.Transform(raw[rows], each Table.FromRows({_}, raw[columns])))),
 //           Output = Table.Join(each Pages, Pages[rows])
            Output = Table.Combine(Pages)
in
    Output

 

With this query, I am able to dynamically fetch my records, page after page, by simply providing the ID of my query on the source website.

 

I read through these already, but it is not clear to me how the solution should apply to my use case:
http://blog.datainspirations.com/2018/02/17/dynamic-web-contents-and-power-bi-refresh-errors/
https://blog.crossjoin.co.uk/2019/04/25/skip-test-connection-power-bi-refresh-failures/

 

Some small help to set it correctly wuold be greatly appreciated 🙂

1 ACCEPTED SOLUTION

I don't like giving up. See my solution below 🙂

(queryID) => let
        resultCount = 1000,
        otherNameForPage = 0,

        GetPage = (otherNameForPage) =>
            let
                content1 = "params={""page"":""" & Number.ToText(otherNameForPage) & """}",
                RawData = Json.Document(Web.Contents(
                    "https://baseURL/admin/plugins/explorer/queries",
                    [RelativePath=Number.ToText(queryID) & "/run",
                        Query=
                        [
                            params="{""page"":""" & Number.ToText(otherNameForPage) & """}"
                        ],

                        Headers = [ 
                        #"api-username"="myUsername",
                        #"api-key"="myAPIKey",
                        #"Content-Type" = "application/x-www-form-urlencoded"],
                        Content = Text.ToBinary(content1)
                    ]
                    
                ) ),
                resultCount = RawData[result_count]
            in
                if RawData[result_count] = 0 then null else RawData,
            Pages = List.Generate(
                () => [i = 0, RawData = GetPage(i)],
                each [RawData] <> null,
                each [i=[i]+1, RawData = GetPage(i)],
                //each Record.ToTable([RawData])),
                each Table.Combine(let raw = [RawData] in List.Transform(raw[rows], each Table.FromRows({_}, raw[columns])))),
 //           Output = Table.Join(each Pages, Pages[rows])
            Output = Table.Combine(Pages)
in
    Output

View solution in original post

3 REPLIES 3
skins
Frequent Visitor

So interesting code @loginerror  ! thank you  🙂

is it possible to add this parameter to it "limit=ALL" ?

I tried many combinations but it doesn't work 

 

thanks again 🙂

v-easonf-msft
Community Support
Community Support

Hi, @loginerror 

Is the issue in the service or desktop?

If in service,you can consider split the original URL into baseURL and RelativePath.
For more details,please refer to this documen.

Using The RelativePath And Query Options With Web.Contents

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

I don't like giving up. See my solution below 🙂

(queryID) => let
        resultCount = 1000,
        otherNameForPage = 0,

        GetPage = (otherNameForPage) =>
            let
                content1 = "params={""page"":""" & Number.ToText(otherNameForPage) & """}",
                RawData = Json.Document(Web.Contents(
                    "https://baseURL/admin/plugins/explorer/queries",
                    [RelativePath=Number.ToText(queryID) & "/run",
                        Query=
                        [
                            params="{""page"":""" & Number.ToText(otherNameForPage) & """}"
                        ],

                        Headers = [ 
                        #"api-username"="myUsername",
                        #"api-key"="myAPIKey",
                        #"Content-Type" = "application/x-www-form-urlencoded"],
                        Content = Text.ToBinary(content1)
                    ]
                    
                ) ),
                resultCount = RawData[result_count]
            in
                if RawData[result_count] = 0 then null else RawData,
            Pages = List.Generate(
                () => [i = 0, RawData = GetPage(i)],
                each [RawData] <> null,
                each [i=[i]+1, RawData = GetPage(i)],
                //each Record.ToTable([RawData])),
                each Table.Combine(let raw = [RawData] in List.Transform(raw[rows], each Table.FromRows({_}, raw[columns])))),
 //           Output = Table.Join(each Pages, Pages[rows])
            Output = Table.Combine(Pages)
in
    Output

Helpful resources

Announcements
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.

June 2025 community update carousel

Fabric Community Update - June 2025

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