Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

[API dotnet] Exception thrown in APIClient.cs with get_cases request


#1

Hello,

I am having some trouble with APIClient.cs and the ‘get_cases’ request…everything seems fine until I reach this line of code:

result = JObject.Parse(text);

The exception thrown is this:
Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path ‘’, line 1, position 1.

I am fairly new to json, so I’m not sure what the issue is…


#2

Hello,

Thanks for your posting. Could you please let me know which API method you’ve tried to call (with parameters)?

Regards,
Tobias


#3

The method I’m calling is get_cases (parameters are project ID and suite ID)

http://docs.gurock.com/testrail-api2/reference-cases

While debugging and stepping through the code, I can see that I am being returned valid Json;

if (text != “”)
{
Debug.WriteLine(text); //****This is fine, ‘text’ is valid Json
result = JObject.Parse(text); //****This is where the exception occurs
}


#4

Thanks for the update. We will make sure to review this and get back to you then. I believe we need to differentiate in the response between objects and arrays and we will try to reproduce this.

Regards,
Tobias


#5

Just to provide you with an update: we could reproduce the behavior and are working on a fix for the .NET API binding right now.

Regards,
Tobias


#6

We’ve now fixed this issue and now return on object of either JArray (when dealing with arrays in the API response) or JObject (when dealing with an object instead). We’ve also already deployed the code to GitHub and you can download the updated code here:

http://docs.gurock.com/testrail-api2/bindings-dotnet

You can then call get_cases as follows:

I hope this helps and please let me know in case you have any questions.

Regards,
Tobias