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

Test Rail Api, method get_case


#1

Hello ,
I am using Test Rail Api using C# and i have a problem to use the method get_case
I’ve made the request https:/mysitehere/testrail/index.php?/api/v2/get_case/:case_id and i got the error : {“error”:“Content-Type header missing (use Content-Type: application/json)”}.
A help will be appreciated.


#2

Hi @kadi,

Thanks for your posting. Do you use our official C# API binding?

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

This would already set the required Content-Type header. If you use a custom integration, you can find the low-level details to access the API here:

http://docs.gurock.com/testrail-api2/accessing

Cheers,
Tobias


#3

I am using http request https:/mysitehere/testrail/index.php?/api/v2/get_case/:case_id
and i don’t really know where to put the content type application/json


#4

You would need to submit this as part of the HTTP headers. What do you use to access the API, our official API binding?

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

Cheers,
Tobias


#5

yep i use the official API binding.
and my program content
JObject cases = (JObject)manager.SendGet(“get_cases/1/1”);

then i have that exception: Additional information: TestRail API returned HTTP 400 (“Field :suite_id is a required field.”).
actually, what i want is to list all test cases in my project (id =1), test suite(id=1) in the console


#6

Hi!

Sure, happy to help. get_cases expects the suite ID as GET parameter as follows:

get_cases/1&suite_id=1

Cheers,
Tobias


#7

Thank you, that help me a lot.
I have an another question: is that a way to convert JObject, JSon Object to a type Case in the TestRail API.
Because when i get my case by using
JObject cas = (JObject)manager.SendGet(“get_case/1”);
cas is a json object and if i want to make things like cas.id or cas.title it’s not gonna work.


#8

Great to hear that this helped :slight_smile: The API always returns JObject or JArray objects currently but you can simply access properties as follows:

cas["id"]

This is loosely typed (but still with a nice/clean syntax) as SendPost and SendGet are generic functions which support all TestRail API methods and you can find a full list of supported properties in the description for each API method:

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

Cheers,
Tobias


#9

Thank you @tgurock,
Finally i manage to convert jarray in list by using that :
JArray plans = (JArray)_manager.SendGet(parameter);
List listplans = cases.ToObject<List>();

Now my problem is to access to properties that is not defined in the constructor like plan[“runs”] .
an idea?


#10

JArray plans = (JArray)_manager.SendGet(parameter);
List listCases = plans.ToObject<List>();

this is the exact code


#11

Which API method are you calling exactly? get_cases or get_plan, for example?

Cheers,
Tobias


#12

it’s get_plan , i found a solution it’s JObject testplan = plan.GetJson();
another question : what can we access to a plan entries like runs
i want to get all my runs from a specific test plan.
thanks for your help


#13

i mean how can we access to a plan entries like runs


#14

The entries attribute returned as part of the get_plan response is an array representing all test plan entries. Each entry contains one or more test runs and this is exposed via the runs attribute on the entry level. Here’s the raw JSON again:

http://docs.gurock.com/testrail-api2/reference-plans#get_plan

I hope this helps!

Cheers,
Tobias


#15

Hi,

I see the same behavior and I think it is a misunderstanding of headers. The documentation says that “Content-Type” is a required header. But for an GET request I have no content and so I need no “Content-Type” header. To specify the wished response format the header “Accept” can be used.

Thanks,
Steffen


#16

Hi Steffen,

Yes, that’s correct but we simplified the API a bit and use the Content-Type header in all cases. We can recommend using one of the API bindings which take care of the headers, authentication, JSON and UTF-8 encoding and error handling:

http://docs.gurock.com/testrail-api2/start

Cheers,
Tobias