ShashwatBisoyi-422 avatar image
0 Votes"
ShashwatBisoyi-422 asked ·

400 error on creating a report using SSRS Rest Api from c# code (ASP core 3.1)

I am getting a 400, bad request error when trying to create a new report using the rest api of ssrs as documented here:

However, I am able to retrieve all the reports and create a folder using similar request. So I suspect the 400 error is in the formatting of json that I am sending (maybe the content variable?). The current json:

   "hasDataSources": true,
   "hasSharedDataSets": true,
   "hasParameters": true,
   "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
   "name": "Test_Report",
   "description": "",
   "path": "/Folder/subfoler/Test_Report",
   "type": 3,
   "hidden": false,
   "size": 0,
   "modifiedBy": "User",
   "modifiedDate": "2021-02-19T11:26:05.323Z",
   "createdBy": "User",
   "createdDate": "2021-02-19T11:26:05.323Z",
   "parentFolderId": "21755bc5a-7a38-4d42-b2de-45c9cacef217",
   "contentType": "application/json",
   "content": "{\"Name\":\"Test\"}",
   "isFavorite": false

The type in the json is an enum with 3 referring to "Report" and 11 to "Report Model". I tried both and still the same 400 error.
Here are the response headers:


edit: fixed quotation mark(my bad) but it is not the problem

image.png (91.1 KiB)
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The on-line sample for “POST /Reports” request uses uppercase properties, such as “HasDataSource” instead of your “hasDataSource”. Maybe the letter case is important.

The “Type” property is described as a string, not number, such as “Unknown” or “Report”. Try "Type": "Report".

Check if other properties are valid according to sample and documentation.

0 Votes 0 ·

For uppercase: The SwaggerUI makes the required conversions to a report object which then gets serialized. I checked in debug mode, all are in proper uppercase format.

The "Type" is an enum defined in the code. I mentioned it just below the json.

There is a mention in code that the "Content" should be
"A string value that contains binary encoding by base64url encoding rules".
I am doing WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(report_obj.Content))
but it returns 400 response

0 Votes 0 ·

1 Answer

DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered ·

Somehow the Json is malformed, and you need to find out why. Offhand, I can't remember some of the Json tools you can use to check the validly of Json data, but they are out there. Maybe you can download a 30 day trial one and check the Json.

· 5 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm aware of what you are saying. I can't figure it out.
The same json works for folder creation but it doesn't take content, content type. There is some problem is in those 2 variables.

0 Votes 0 ·

If you have control of the client and WebAPI, you could use a custom class, like a DTO to hold the data and send the DTO which would be using encapsulation and information hiding so the data would not be inspected inside the DTO as it is Json serialized and deserialized.

0 Votes 0 ·

I only have access to the client code.
Currently I am using HttpClient and a HttpRequestMessage to send the data as httpClient.SendAsync(httpRequestMessage). The above json is serialized and added to the HttpRequestMessage object. Does is not work as a DTO? I don't know about it.

I tried with restsharp too. Got same results(GET methods working, Folder creation working but can't create a report)

0 Votes 0 ·
Show more comments