'Unable to fetch data from test rail using java
I am using the API provided by Test rail to pull info using java. Below is my program.
APIClient client = new APIClient("https://test.testrail.net/index.php?/runs/view/154"); client.setUser("..");
client.setPassword("..");
JSONObject c = (JSONObject) client.sendGet("get_case/T54757");
System.out.println(c);
I downloaded the API and called the method as mentioned above.But every time the json response is returning null. Could any body please help?
Solution 1:[1]
As per TestRail API V2- one needs to use TYPE= Basic Authentication and UserName= and Password=<your testrail password or API key, if enabled>
It's strongly advised to enable API key and use it when accessing with code for security reasons. Whole collections of API calls, working fine for me.
Solution 2:[2]
There are a couple of potential issues with your code, but they should be pretty easy fixes. First, you should initialize the client with just the base URL for the API, without writing any specific endpoint. After that, update the case ID to be totally numeric, without the T
or C
prefix.
Here’s what that might look like based on the code you shared:
APIClient client = new APIClient("https://test.testrail.net/index.php?/api/v2");
JSONObject c = (JSONObject) client.sendGet("get_case/54757");
To test the request manually (i.e. using Postman), you could use something like the example below and pass your TestRail username/password as Basic Authentication:
GET https://test.testrail.net/index.php?/api/v2/get_case/123
See the get_case documentation reference for more details: https://www.gurock.com/testrail/docs/api/reference/cases/#getcase
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Atul Kumar Sharma |
Solution 2 | Diogo Rede |