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

Troubleshooting API 400 error


I`m getting 400 error message, but my test case id is defiantly right.

com.gurock.testrail.APIException: TestRail API returned HTTP 400(“Field :case_id is not a valid test case.”)

at com.gurock.testrail.APIClient.sendRequest(
at com.gurock.testrail.APIClient.sendPost(
at config.TestRailSetup.sendResultsToTestrail(
at foundation.LoginTestTest.toTestrail(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.testng.internal.MethodInvocationHelper.invokeMethod(
at org.testng.internal.Invoker.invokeConfigurationMethod(
at org.testng.internal.Invoker.invokeConfigurations(
at org.testng.internal.Invoker.invokeMethod(
at org.testng.internal.Invoker.invokeTestMethod(
at org.testng.internal.Invoker.invokeTestMethods(
at org.testng.internal.TestMethodWorker.invokeTestMethods(
at org.testng.TestRunner.privateRun(
at org.testng.SuiteRunner.runTest(
at org.testng.SuiteRunner.runSequentially(
at org.testng.SuiteRunner.privateRun(
at org.testng.SuiteRunnerWorker.runSuite(
at org.testng.TestNG.runSuitesSequentially(
at org.testng.TestNG.runSuitesLocally(
at org.testng.RemoteTestNGStarter.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.intellij.rt.execution.application.AppMain.main(

I have test automation framework with page object model. ( java + testng+ appium )
My Test:

package foundation;

import com.gurock.testrail.APIClient;
import com.gurock.testrail.APIException;
import com.moo.webcalls.AOWebClient;
import com.pageobjects.HamburgerMenuList;
import com.pageobjects.HeaderMenu;
import config.LogIn;
import config.LogOut;
import config.DesiredCapabilitiesSetup;
import config.TestRailSetup;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import org.testng.ITestResult;
import org.testng.annotations.*;
import org.testng.asserts.SoftAssert;

import java.lang.reflect.Method;

public class LoginTestTest {
public AndroidDriver driver;
public AOWebClient aoWebClient;
APIClient client;
int runID;
int caseID;
ITestResult result;

AOWebClient aoWeb;
public LoginTestTest(AndroidDriver<AndroidElement> driver, AOWebClient aoWeb){
    this.driver = driver;
    this.aoWeb = aoWeb;
    PageFactory.initElements(new AppiumFieldDecorator(driver), this);
public LoginTestTest() {
SoftAssert softAssert = new SoftAssert();
public void setUp() throws Exception {
    driver = DesiredCapabilitiesSetup.startAppiumServer();
    aoWebClient = DesiredCapabilitiesSetup.getAOWeb();
    client = TestRailSetup.myClient();
    runID = TestRailSetup.TestrailID();
    LogIn logIn = new LogIn(driver,aoWebClient);
public void goToSettings() throws InterruptedException,IOException {
    caseID =29;
    HeaderMenu header = new HeaderMenu(driver,aoWeb);
    HamburgerMenuList ham = new HamburgerMenuList(driver);
public void toTestrail(ITestResult result) throws MalformedURLException, IOException, APIException {
    // System.out.println("Result: "+result);
    TestRailSetup.sendResultsToTestrail(client, result, runID, caseID);
public void tearDown() throws Exception {
    LogOut logOut = new LogOut(driver,aoWeb);


TestRailSetup file:

package config;

import java.util.HashMap;
import java.util.Map;

import org.testng.ITestResult;

import com.gurock.testrail.APIClient;
import com.gurock.testrail.APIException;
public class TestRailSetup{

public static APIClient myClient(){
    APIClient client;
    client = new APIClient("");    // i hide it
    client.setUser("userName");// i hide it
    client.setPassword("password");// i hide it
    return client;
public static int TestrailID(){
    int runID=5;
    return runID;
public static void sendResultsToTestrail (APIClient client, ITestResult result, int runID, int caseID) throws MalformedURLException, IOException, APIException {
    Map<String,Integer> data = new HashMap<String,Integer>();
    int Status=new Integer(result.getStatus());
    if (Status==2){

//System.out.println("Parameters: "+result.getParameters());
// System.out.println(“method name: " + result.getMethod().getMethodName() + " status: “+Status);
data.put(“status_id”, Status);
client.sendPost(“add_result_for_case/”+runID+”/”+caseID, data);

And APIClient and APIExceptions files add as default.

My Test Run is definitely number 5 and TC is number 29:

How i can troubleshoot why it`s not able to locate TC ?


I think i found what was the problem.
I was pointing to T29 instead of pointing to C2.


Hi Anton,

Thanks for your posting! Yes, the case ID refers to the C### numbers and the T### numbers would be test IDs instead. Good to hear that it works now and please let us know in case anything else comes up.



APIClient client = new APIClient(“http://…/testrail/”); //hidden
client.setUser("…"); //hidden
client.setPassword("…"); //hidden
JSONObject c = (JSONObject) client.sendGet(“get_case/C596794”);

I’m also getting the same error , case
_id is invalid , whereas my test run is


The case_ID in the get_case call should be 596794, without the C.


I’m still getting the same error ?
one more doubt do i need to give the above complete url in API client constructor or only till /testrail


I think I see the issue. The URL you posted is to view the test, not the case. If you view that test in TestRail and click the View Case button you’ll be taken to the test case where you can get the case_id.


Yes Donalaya , i was looking in the wrong URL. Its working now .Thanks !!


Hey Jatin,

Thank you for the update. We are glad to read that this is working for you now.


Hi Martylavender,

Can you provide me an example of how test rail API should get integrated with a Automation framework to fetch the data from test rail and to send the data to test rail, a fully functional code


Hi Jatin,

Thank you for the reply. This really would depend on what you are wanting to integrate TestRail with and if you are using a specific language i.e., JAVA, etc. Our API documentation gives simple request examples and we also have several different language bindings available on our site.