0

Need to get page list of a Report based on ReportId from powerbi in my web api project. Couldn't find any option in power bi client object for fetching page info in C# web api. Tried using HttpClient then but still getting forbidden error with below code-

        var accessToken = await GetAccessToken(authMode);
        client.BaseAddress = new Uri("https://api.powerbi.com/v1.0/myorg/");
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);

        HttpResponseMessage response = await client.GetAsync("reports/" + reportId);
        if (response.IsSuccessStatusCode)
        {
            var pageList = await response.Content.ReadAsAsync<List<PageInfo>>();
            return pageList;
        }
        return Enumerable.Empty<PageInfo>();

2 Answers 2

1

There is currently no way you can get all the pages of a report based on reportId using C# Web API.

Please check:
https://community.powerbi.com/t5/Developer/Get-List-Of-Report-Pages-via-C-Rest-API/m-p/376293

However, you can use powerbi-client (JS SDK) to get all the pages of a report.

Please refer below code:

// reportContainer: HTML div element in which report is being embedded
// config: Report embed configuration object
const report = powerbi.embed(reportContainer, config);
const pages = await report.getPages();

// pages is an array which contains all the pages available for the given report.
console.log(pages);

Please refer here:

  1. https://learn.microsoft.com/javascript/api/powerbi/powerbi-client/report.report#getPages__
  2. https://learn.microsoft.com/rest/api/power-bi/reports/get-pages
Sign up to request clarification or add additional context in comments.

Comments

0

It looks like this is now possible:

var report = await pbiClient.Reports.GetReportInGroupAsync(WorkspaceId, ReportId);
var pages = await pbiClient.Reports.GetPagesInGroupAsync(WorkspaceId, ReportId);

(using Microsoft.PowerBI.Api v4.18.0)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.