How to send an API request to TestRail to update the status as passed .

For that I used Rest Assured with Java and below code snippet.

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.json.JSONObject;

public void sendTestResultOfTestCase() {
String username = "myusername";
String password = "mypassword";
String runId = "29798"; //Remove the starting English letter R29798 , so it's 29798
String testCaseId = "1827330"; // Remove the starting English letter
String endpoint = "https://skynet.testrail.net/index.php?/api/v2/add_result_for_case/" + runId + "/" + testCaseId;
JSONObject requestParams = new JSONObject();

requestParams.put("status_id", "1"); // 1 means pass
requestParams.put("comment", "Hi, this test was passed via automation."); // optional comment.
requestParams.put("case_id", testCaseId);
requestParams.put("run_id", runId);
Response response = RestAssured.given().auth().preemptive().basic(username, password)
.contentType("application/json")
.body(requestParams.toString())
.when()
.post(endpoint);
System.out.println(response.getBody().asString());


}

1 means pass and two means blocked, 4 means retest and 5 means fail.

Dependencies that needed

            <dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>

No responses yet