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

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

Accepted Solutions
Highlighted
Frequent Visitor

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

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

Highlighted
Frequent Visitor

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

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
Highlighted
Super User III
Super User III

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

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"

  

Highlighted
Frequent Visitor

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

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

Highlighted
Super User III
Super User III

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


@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

Highlighted
Frequent Visitor

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

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

Highlighted
Super User III
Super User III

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

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

Helpful resources

Announcements
Community Blog

Community Blog

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

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors