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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
lsteffens
Advocate I
Advocate I

Problem setting CacheOptions and expiration schedule via REST API (V2.0) in C#/Swagger API

I use the downloaded and compiled Swagger API for Power BI Resort Server and I'm able to list content (e.g. Reports) (GET request) or upload content (e.g. PBIReport or paginated report) (POST request) using C#.

 

But I have problems updating items with the REST API (PUT request):

For example I need to update the CacheOptions of a (paginated) report.

 

Here are the relevant code fragments:

1.: get the ReportsAPI client object

 

 

// get the ReportsAPI client object
var client = new ReportsApi(apiString);

 

 

 

... do authentication (Forms) and get a report object (I ommited the code ...) ...

 

2.: get the CacheOptions object of a uploaded paginated report

 

 

// works - I get the CacheOptions object
CacheOptions co = client.GetReportCacheOptions(report.Id.ToString());

 

 

 

3.: immediately try to update the report by setting the CacheOptions object (unmodified in this sample) on the report

 

 

// does not work - I get an exception inside of the Swagger API
client.SetReportCacheOptions(report.Id.ToString(), co); // just a test ...

 

 

 

On step 3. I have the problem that an exception within Swagger ReportsAPI is thrown:

The property 'ScheduleId' does not exist on type 'Model.ScheduleReference'. Make sure to only use property names that are defined by the type.

 

Trying to redo the steps with the help of Postman gives me a error 500 (internal server error) when trying to put a CacheOption JSON in the raw body (URL="https://myserver/reports/api/v2.0/Reports(690f6c2a-8995-4d29-bbd4-a4b2cc839bcb)/CacheOptions")

 

I have this kind of problem while using this coding approach not only for CacheOptions but for all other PUT requests I tested.

 

Maybe someone can help me out with this?

Thanks, Lars

2 ACCEPTED SOLUTIONS

Thanks for your post - it was really helpful as I got a working body text for postman to get to the real error (inside the swagger API).

I already set the content type for the body to raw and JSON in postman and the swagger API does set it correctly, too. There was something wrong with the body test I used.

 

The real problem was that in my tests I use a schedule defined in power bi ui and did not give the expiration schedule in the body of my request (like you did in your sample ...).

 

While debugging the Swagger API for power bi I noticed that the "ScheduleID" is used case sensitive in the REST API request.

 

Swagger made this request body:

This does not work as "ScheduleId" is wrong:

{"ExecutionType":"Cache","Expiration":{"Minutes":0,"Schedule":{"ScheduleId":"e4bd295b-15b6-4986-9376-aa890fe937d1"}}}

 

This works correct:

{"ExecutionType":"Cache","Expiration":{"Minutes":0,"Schedule":{"ScheduleID":"e4bd295b-15b6-4986-9376-aa890fe937d1"}}}

 

Funny that the "official" REST API documentation has this bug and I wonder why the REST API names are case sensitive at all ... ^^

 

So I need to solve the problem in the Swagger C# Schedule class and use the correct name ...

View solution in original post

As a follow up ....

 

You have to change "ScheduleId" to "ScheduleID" in this code row in "ScheduleReference.cs" of the downloaded C# Swagger API:

 

[DataMember(Name="ScheduleID", EmitDefaultValue=false)]

 

 

... and it works in my case.

View solution in original post

5 REPLIES 5
d_gosbell
Super User
Super User

Are you setting the Content-Type on the PUT request to "application/json" ?

 

I turned on the dev tools in my browser then grabbed the url and body of the request and replayed it in Powershell using the following and I can change the cache expiration minutes and see it reflected in the UI

 

$body = '{"Id":"00000000-0000-0000-0000-000000000000","ExecutionType":"Cache","Expiration":{"Minutes":15,"Schedule":null}}'

$url = "http://localhost/reports/api/v2.0/reports(ab44aa41-496e-47a2-8ad5-fd5f8b8428fc)/CacheOptions"

$res = Invoke-RestMethod -Method Put -Uri $url -UseDefaultCredentials -Body $body -ContentType "application/json"

  

Thanks for your post - it was really helpful as I got a working body text for postman to get to the real error (inside the swagger API).

I already set the content type for the body to raw and JSON in postman and the swagger API does set it correctly, too. There was something wrong with the body test I used.

 

The real problem was that in my tests I use a schedule defined in power bi ui and did not give the expiration schedule in the body of my request (like you did in your sample ...).

 

While debugging the Swagger API for power bi I noticed that the "ScheduleID" is used case sensitive in the REST API request.

 

Swagger made this request body:

This does not work as "ScheduleId" is wrong:

{"ExecutionType":"Cache","Expiration":{"Minutes":0,"Schedule":{"ScheduleId":"e4bd295b-15b6-4986-9376-aa890fe937d1"}}}

 

This works correct:

{"ExecutionType":"Cache","Expiration":{"Minutes":0,"Schedule":{"ScheduleID":"e4bd295b-15b6-4986-9376-aa890fe937d1"}}}

 

Funny that the "official" REST API documentation has this bug and I wonder why the REST API names are case sensitive at all ... ^^

 

So I need to solve the problem in the Swagger C# Schedule class and use the correct name ...


@lsteffens wrote:

 

Funny that the "official" REST API documentation has this bug and I wonder why the REST API names are case sensitive at all ... ^^

 


Well JSON is a case-sensitive format so it makes sense that ScheduleId and ScheduleID are treated differently, but I don't know how that bug would have slipped into the docs on Swaggerhub I would have expected those to be generated from somewhere

As a follow up ....

 

You have to change "ScheduleId" to "ScheduleID" in this code row in "ScheduleReference.cs" of the downloaded C# Swagger API:

 

[DataMember(Name="ScheduleID", EmitDefaultValue=false)]

 

 

... and it works in my case.

I've flagged this with some contacts I have at Microsoft to see if they can get SwaggerHub corrected.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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