Happy Business Starts Here

Highlighted
Honor Student

HTTP 500 : Internal Server Error using RestSharp client

Tried everything and scoured the forum. I'm sure the json being generated is well formed. Here's a minimalisitc sample that gives the 500 error:

 

=======================

 

string url = "https://www.zuora.com/apps/api/batch-query/";

 

var client = new RestClient(url)
{
  Authenticator = new HttpBasicAuthenticator(UserName, Password)
};

 

var request = new RestRequest(Method.POST);

request.AddParameter("format", "csv");
request.AddParameter("version", "1.0");

 

var theName = "Example";
var theQuery = "select AccountId, FirstName, LastName from contact where State='California'";

 

var queryArrayJson = JsonConvert.SerializeObject(new object[] {
  new {
    name = theName,
    query = theQuery,
    type= "exportzoql"
 }
});

request.AddParameter("queries", queryArrayJson);

 

var response = client.Execute(request);

return response.Content;

 

=======================

 

Can anyone help?

3 REPLIES 3
Honor Student

Re: HTTP 500 : Internal Server Error using RestSharp client

Also getting the same 500 error using Postman.

Master

Re: HTTP 500 : Internal Server Error using RestSharp client

Hi @mch2112!

 

It is a simple mistake (but I also often make same type mistakes).

The character string specified for Type is zoqlexport (not exportzoql).

https://knowledgecenter.zuora.com/DC_Developers/T_Aggregate_Query_API/B_Submit_Query

 

I ran this on Postman and received a normal response.

AQuA_example.png

 

The way to confirm the result of this request from Zuora UI is as follows:
(Login) > Settings > Reporting > AQuA job finder

 AQuA_jobfinder.png

 

Honor Student

Re: HTTP 500 : Internal Server Error using RestSharp client

Thanks yamasaki1ma, that was an error! But there was a bigger error which I have figured out. I was encoding the query as JSON but using normal parameters otherwise. It seems nessesary to encode the entire request as JSON. So, this seems to work:

 

var reqJson = new
{
  format = "csv",
  version = "1.0",
  queries = new object[] {
    new {
    name = theName,
    query = theQuery,
    type = "zoqlexport"
  }
}
};

request.RequestFormat = DataFormat.Json;
request.AddBody(reqJson);

var response = client.Execute(request);