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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
Fabio_Franchi
New Member

PowerBI Embedded API ExportToFileInGroupAsync - BAD Request when using Bookmark state

Hi all,

I have a code (FE Angular, BE c#) that run smoothly to export a PowerBI report in a file (e.g. PDF) from a Gen v2 PowerBI embedded.
The trouble is when I try to use a state (the running state of the report, e.g. the selection operates by the user by filters) obtained in the front end by the couple bookmarksManager.capture and capturedBookmark.state.

 

Notice that capturedBookmark.state is truly a string that resemble a serialized "something".
But when I use that string to recreate the bookmark object in the BE and pass it to ExportToFileInGroupAsync (c# API) I receive a 400 Bad Request.

 

Without passing the Bookmark (passing a null) everything works but I obviously obtain the default report aspect (the one I saved when I published the report to the service).

 

Has someone a piece a code to share to help me to find the error or faced similar troubles?

 

Thanks a lot

Fabio

7 REPLIES 7
Jesus_Sanchez
New Member

Hi @Fabio_Franchi  I got stucked on the same issue that you have ad I hope you already solved but if not or someone more is looking for this in my case was solved it just sending the PageBookmark State string on the exportRequest object. The error was that I was sending the PageBookmark Name and PageBookmark State. According to this definitions https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file PageBookmark must provide the Name or the Satate, but not both.

v-yinliw-msft
Community Support
Community Support

Hi @Fabio_Franchi ,

 

Do you have some RLS or the custom visual?

If not , you can check your API code request and It may lack something.

It will give you the error's detail.

 

Hope this helps you.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Hi, 

 

No RLS.

It's quite hard but I tried to extract the code.

 

In the FE (Angular)

 

var bookmark= await embed.bookmarksManager.capture();
var state= bookmark.state

 

then I pass the state in the BE (c# .NET) as a string and recreate a bookmark with

 

PageBookmark bookmark = new PageBookmark(state:state);

 

NOTE: I found in the documentation that a valid bookmark can have only name or state not both

 

Later in the BE create an ExportReport Settings

 

Settings = new ExportReportSettings
{
Locale = "en-us",
},
DefaultBookmark = bookmark, /// <-- I USE THE STATE HERE
Pages = pageNames?.Select(pn => new ExportReportPage(pn)).ToList(),
Identities = new List<EffectiveIdentity>() {new EffectiveIdentity()
{
Roles = new List<string>() { "role1" },
Username = id_execution,
Datasets = new List<string>() { dataset_id }
}
}

 

And finally I call the API

 

var export = await Client.Reports.ExportToFileInGroupAsync(groupId, reportId, exportRequest);

 

But it returns a generic "Bad Request"

 

I hope this better clarify my trouble (and/or my error)

 

Thanks

Fabio_Franchi
New Member

Thank you for the fast reply,

 

My code is based on that documentation and, as far as a I understood, it has all the requisites.

 

In particular, I used as a model the section in which it describe the method to export the report's state.

 

Fabio_Franchi_0-1666603004387.png

 

And if I avoid the use of a bookmark create on the fly (the only obvious way to catch the running state of a report embedded in an iFrame) everything works.

 

The part of my code involved in the export is not so easy to extract (is an azure app) but, I swear, is a bare adapted cut&paste of the sample code I found in the documentation you mention.

 

Sorry but I still in stuck

 

Fabio

 

Hi @Fabio_Franchi ,

 

Security/Firewall may also cause this issue when it was terminating the SSL connection. You can add a bypass for the URL to try whether it works.

 

Hope this helps you.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi,

 

I think it's not related to firewall or security.

The code works if I don't specify the bookmark.

 

v-yinliw-msft
Community Support
Community Support

Hi @Fabio_Franchi ,

 

There are some limitations and considerations for Exporting Power BI report to file.

vyinliwmsft_0-1666599990946.png

Other limitations are here:

Export Power BI embedded analytics reports API - Power BI | Microsoft Learn

If your bookmark is not personal bookmark, you can also check your code by referring the example in the documentation.

Export Power BI embedded analytics reports API - Power BI | Microsoft Learn

 

Hope this helps you.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.