cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

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
Super User V
Super User V

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
Helper I
Helper I

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 Community Highlights

Check out a full recap of the month!

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.