cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Operation returned an invalid status code 'Forbidden while executing ExportToFileInGroupAsync

https://docs.microsoft.com/en-us/power-bi/developer/embedded/export-to

 

By using the above document link, i tried to export a power bi report from an application using this code in .net core framework.


var powerBIReportExportConfiguration = new PowerBIReportExportConfiguration
{
Settings = new ExportReportSettings
{
Locale = "en-us",
},
Pages = pageNames?.Select(pn => new ExportReportPage(pageName = pn)).ToList(),
};
var exportRequest = new ExportReportRequest
{
Format = format,
PowerBIReportConfiguration = powerBIReportExportConfiguration,
};

 

var url = XXX;
var content = new Dictionary<string, string>();
content["grant_type"] = "XXX";
content["resource"] = "XXX";
content["username"] = XXX;
content["password"] = XXX;
content["client_id"] = XXX;

var response = await APIHelper.MakeAsyncRequest(url, content);
var tokenresult = response.Content.ReadAsStringAsync().Result;
var OAuthResultModel = JsonConvert.DeserializeObject<OAuthResultModel>(tokenresult);
var authenticationResult = OAuthResultModel;

var credentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
var client = new PowerBIClient(credentials);
var reportsResult = await client.Reports.ExportToFileInGroupAsync(GroupID, ReportID, exportRequest);

While executing the last line, code break and through an exception, i.e.:

 

{"Operation returned an invalid status code 'Forbidden"}

2 REPLIES 2
Highlighted
Community Champion
Community Champion

Re: Operation returned an invalid status code 'Forbidden while executing ExportToFileInGroupAsync

Does it work in the sandbox?

 

https://docs.microsoft.com/en-us/rest/api/power-bi/reports/exporttofileingroup

 

(click the Try it button)

Highlighted
Frequent Visitor

Re: Operation returned an invalid status code 'Forbidden while executing ExportToFileInGroupAsync

yes. This kind of json returned with status code 200.

saadashraf_0-1593749719026.png

 

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

We are thrilled to announce we will begin running a monthly webinar series named Power BI Dev Camp.