Happy Business Starts Here

Re: AQuA API - Internal Server Error

Highlighted
Valued Scholar

AQuA API - Internal Server Error

 

I am running into an "Internal server Error" on making the AQuA API POST Request with a ZOQL through a custom C# code. I am using RestClient. 

 

The POST request is made to https://apisandbox.zuora.com/apps/api/batch-query/ .

 

The Response doesn't give any more details. what could be the cause? 

 

Is there a C# sample available ?

 

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

 

 

 

9 REPLIES 9
Highlighted
Zuora Staff

Re: AQuA API - Internal Server Error

Hi @gbordawekar

 

Can you post the full details and JSON payload of this call?  An "Internal server error" is somewhat generic, which could be due to header or payload syntax or as simple as an incorrect URL path in your batch-query POST



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √


Highlighted
Valued Scholar

Re: AQuA API - Internal Server Error

 

The code (C#) - 

 

string sBaseURL;
string sUsername = "";
string sPassword = "";

 

//Sandbox

sBaseURL = "https://apisandbox.zuora.com/apps/api/batch-query/";
sUsername = "gbordawekar@ZuoraFullsand.com";
sPassword = "<enter your password>";

 

var client = new RestClient(sBaseURL);
client.Authenticator = new HttpBasicAuthenticator(sUsername, sPassword);

 

//JSON array object to hold the Queries data
QueryHolder[] queriesArr = new QueryHolder[]
{
new QueryHolder()
{
name = "AccountingPeriod",
query = "select Id,StartDate,EndDate,FiscalYear,Name,Status from AccountingPeriod",
type = "zoqlexport"
},
};

 

JavaScriptSerializer js = new JavaScriptSerializer();
string queriesJson = JsonConvert.SerializeObject(queriesArr);

var request = new RestRequest(Method.POST);
request.AddParameter("format", "csv");
request.AddParameter("version", "1.1");
request.AddParameter("name", "Example");
request.AddParameter("encrypted", "none");
request.AddParameter("useQueryLabels", "true");
request.AddParameter("project", System.DBNull.Value);
request.AddParameter("partner", System.DBNull.Value);
//request.AddParameter("notifyurl", " "); // TBD
request.AddParameter("dateTimeUtc", "true");
request.AddParameter("queries", queriesJson);

 

// execute the request
IRestResponse response = client.Execute(request);                 =>  Returns the "Internal Server Error" 
var content = response.Content; // raw content as string              

 

//JavaScriptSerializer js = new JavaScriptSerializer();
var dict = js.Deserialize<Dictionary<string, dynamic>>(response.Content);

 

Highlighted
Zuora Staff

Re: AQuA API - Internal Server Error

Can you post the raw JSON output (outside of the your code).  We really need to see how the JSON is constructed in this case as the Zuora app may be rejecting based on syntax.  Ideally, id like to see the full payload (including HTTP headers with any Authentication redacted) and the full URL used so I can see what you're sending to the Zuora app.



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √


Highlighted
Valued Scholar

Re: AQuA API - Internal Server Error

This is all I could capture  -

 

POST https://apisandbox.zuora.com/apps/api/batch-query/ HTTP/1.1
Accept: application/json
Authorization: ####
User-Agent: RestSharp/105.2.3.0
Content-Type: application/x-www-form-urlencoded
Host: apisandbox.zuora.com
Content-Length: 329
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

format=csv&version=1.1&name=Example&encrypted=none&useQueryLabels=true&dateTimeUtc=true&queries=%5B%7B%22name%22%3A%22AccountingPeriod%22%2C%22query%22%3A%22select%20Id%2CStartDate%2CEndDate%2CFiscalYear%2CName%2CStatus%20from%20AccountingPeriod%22%2C%22type%22%3A%22zoql%22%2C%22apiversion%22%3Anull%2C%22deleted%22%3Anull%7D%5D

 

=========

PostMan also receives the 500 error and had the following in the request - 

 

var settings = {
"async": true,
"crossDomain": true,
"url": "https://apisandbox.zuora.com/apps/api/batch-query/",
"method": "POST",
"headers": {
"authorization": "####",
"content-type": "application/x-www-form-urlencoded",
"cache-control": "no-cache",
"postman-token": "1253560a-0b9a-73b1-b0ab-1a2668a3fe07"
},
"data": {
"format": "csv",
"version": "1.1",
"name": "Example",
"encrypted": "none",
"useQueryLabels": "true",
"dateTimeUtc": "true",
"queries": "[ { \"name\" : \"AccountingPeriod\", \"query\" : \"select Id,StartDate,EndDate,FiscalYear,Name,Status from AccountingPeriod\", \"type\" : \"zoqlexport\" }]"
}
}

$.ajax(settings).done(function (response) {
console.log(response);
});

 

 

Highlighted
Zuora Staff

Re: AQuA API - Internal Server Error

Content-Type: should proably be

application/json

 

Can you see if changing this helps?



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √


Highlighted
Valued Scholar

Re: AQuA API - Internal Server Error

I updated the "content-type" to "application/json". and here 's the updated PostMan request header and the response.

 

var settings = {
"async": true,
"crossDomain": true,
"url": "https://apisandbox.zuora.com/apps/api/batch-query/",
"method": "POST",
"headers": {
"authorization": "###",
"content-type": "application/json",
"cache-control": "no-cache",
"postman-token": "4ff4115f-a1ac-2e22-b588-4b3ce852aeab"
},
"data": {
"format": "csv",
"version": "1.1",
"name": "Example",
"encrypted": "none",
"useQueryLabels": "true",
"dateTimeUtc": "true",
"queries": "[ { \"name\" : \"AccountingPeriod\", \"query\" : \"select Id,StartDate,EndDate,FiscalYear,Name,Status from AccountingPeriod\", \"type\" : \"zoqlexport\" }]"
}
}

$.ajax(settings).done(function (response) {
console.log(response);
});

 

Response from Zuora - 

 

{"Error":"Could not read JSON: Unrecognized token 'fomtcvvrin11nm': was expecting 'null', 'true', 'false' or NaN\n at [Source: org.apache.catalina.connector.CoyoteInputStream@646cdfdc; line: 1, column: 29]; nested exception is org.codehaus.jackson.JsonParseException: Unrecognized token 'fomtcvvrin11nm': was expecting 'null', 'true', 'false' or NaN\n at [Source: org.apache.catalina.connector.CoyoteInputStream@646cdfdc; line: 1, column: 29]"}

 

 

Highlighted
Community Manager

Re: AQuA API - Internal Server Error

Hi @gbordawekar,

 

I've edited out your authorization token.  Please make sure that you edit that out in your posts 😉

 

Thanks for visiting the community!  You're in good hands with @scottb.

 

Lana


Lana Lee | Senior Community Manager and Strategist
"A little consideration, a little thought for others, makes all the difference." —A. A. Milne
Highlighted
Zuora Staff

Re: AQuA API - Internal Server Error

I had to clean this up your specific syntax somewhat to pass as valid JSON using the JSONLint tool - I realize your own code may require those escapes to work.  I also had to remove an extra set of double-quotes around the query parameters for the API to accept it.

 

 

{
	"format": "csv",
	"version": "1.1",
	"name": "Example",
	"encrypted": "none",
	"useQueryLabels": "true",
	"dateTimeUtc": "true",
	"queries": [{
		"name": "AccountingPeriod",
		"query": "select Id,StartDate,EndDate,FiscalYear,Name,Status from AccountingPeriod",
		"type": "zoqlexport"
	           }]
}

 

Passing the above JSON works, although I have not tried with your specific headers.  I'm only passing Content-Type: and Authorization: as a minimum requirement.  Looking at your supplied output, it seems like you're passing the "queries" arguments in double-quotes

 

"queries": "[{...}]"

 

Again, you need to remove the quotes around the brackets changing to the following:

 

"queries": [{...}]

 

...and possibly the escapes around this same section depending on how your code generates the request.  The above JSON will produce a valid request response from the API when I use ARC (Chrome Advanced REST client) and should work in Postman as-is. 

 

Hopefully this is a simple matter of synax and clean-up on the JSON output from your code. 



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √


Highlighted
Newly Enrolled

Re: AQuA API - Internal Server Error

Validate JSON using this tool: JSON Formatter

Tags (1)