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

TestRail API returned HTTP 400("Field :run_id is not a valid ID.")

Hi ,
I’m new to integrate the Testrail with with selenium using java here is my code and the error i’m getting like this below.

`public class TestrailFirstSample {

public static String TEST_RUN_ID                = "R3";
public static String TESTRAIL_USERNAME          = "";
public static String TESTRAIL_PASSWORD          = "PackageX@123";
public static String RAILS_ENGINE_URL           = "";
public static final int TEST_CASE_PASSED_STATUS = 1;
public static final int TEST_CASE_FAILED_STATUS = 5;
WebDriver driver;

@Test(description = "tetstes")
public void verifyTitle() throws Exception, APIException {
	System.setProperty("", System.getProperty("user.dir") + "/drivers/chromedriver.exe");
    driver= new ChromeDriver();
    String actualTilte = driver.getTitle();
    if (actualTilte.contains("Google")) {
        TestrailFirstSample.addResultForTestCase("C1", TEST_CASE_PASSED_STATUS, "");

TestrailFirstSample.addResultForTestCase(“C1”, TEST_CASE_FAILED_STATUS, “”);


public static void addResultForTestCase(String testCaseId, int status,
        String error) throws IOException, APIException {

    String testRunId = TEST_RUN_ID;

    APIClient client = new APIClient(RAILS_ENGINE_URL);
    Map data = new HashMap();
    data.put("status_id", status);
    data.put("comment", "Test Executed - Status updated automatically from Selenium test automation.");
    client.sendPost("add_result_for_case/"+testRunId+"/"+testCaseId+"",data );



TestRail API returned HTTP 400(“Field :run_id is not a valid ID.”)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(
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.TestNG.runSuites(
at org.testng.remote.RemoteTestNG.initAndRun(
at org.testng.remote.RemoteTestNG.main(

Do not include he leading T, C, R is any API call. Those are added for the UI but in the table the ID is just the number.

I didn’t get your point could you please explain

R3 is not a valid Test Run Id - 3 is. The R is added for the UI only, the actual ID on the database table is 3.

So in the call - drop the R for the Run ID and only use “3”.

Okay Got it Thank you so much let me Run this again

Now error is appearing like
TestRail API returned HTTP 400("Field :case_id is not a valid ID.

C1 is not a valid test case - just use the 1 and not the C1 for the Case Id. The alpha characters in the UI are just for the UI and not used in the DB.

1 Like

Thank you so much its worked :slight_smile:

1 Like