function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vinod kumar 164vinod kumar 164 

Sample code for fetching Asynchronous report call using HtpWebRequest (Rest Api)

Hi

We are new to the salesforce and we are trying to integrate our App to salesforce.
Right now we are trying to fetch the particular reports data from salesforce using HttpWebrequest(Rest Api) using c# code.
we are implementing asynchronous report call with post request body to get the data but we are unable to get and it is throwing exception that is
[{"message":"The request body is either invalid or incomplete.","errorCode":"JSON_PARSER_ERROR"}]

So please provide us with sample code for fetching the reports with asynchronous call and also tell us how to send post request body for asynchronous report call  for fetching reports data.

Regards
vinod
Daniel BallingerDaniel Ballinger
What code do you currently have? There is likely something wrong with the JSON body that you are POSTing.

There is a good example of the raw HTTP calls required in Example of an asynchronous report run (https://developer.salesforce.com/docs/atlas.en-us.200.0.api_analytics.meta/api_analytics/sforce_analytics_rest_api_get_reportdata.htm#example_report_async_instances)

I know with my other REST API class from .NET it is important to write the JSON form data to the request stream correctly and to specify the ContentLength. What does your JSON for the POST body look like?
Aaron MelgarAaron Melgar
payload = {"reportFormat": "TABULAR"}
r = sf_session.post(f"{sf_url}/services/data/v47.0/analytics/reports/{report_id}/instances", json=payload)

I get the same error with the above code. Per the docs I can add the reportFormat setting in my payload but get this error:
[{"message":"The request body is either invalid or incomplete.","errorCode":"JSON_PARSER_ERROR"}]

https://developer.salesforce.com/docs/atlas.en-us.222.0.api_analytics.meta/api_analytics/sforce_analytics_rest_api_instances_summaryasync.htm