API: Accessing the API
TestRail's API is HTTP-based and you can use simple HTTP requests to interact with it. All write requests must use the HTTP POST method, and all read requests must use the HTTP GET method. To authenticate the requests against the API, you simply need to append the API key to all requests as an argument. The following example shows a simple request to read a test case. We use the cURL command line tool to send the request in this example, but any HTTP tool or library will work:
$ curl -H "Accept: application/json" \ "https://example.testrail.com/index.php?/miniapi/get_case/2&key=12345678"
The parts of this request in detail:
| Part | Description |
|---|---|
| “Accept: application/json” | A required header |
| https://example.testrail.com/ | The server address |
| index.php?/miniapi/ | The path of TestRail's API |
| get_case | The API method that is called |
| /2 | An argument for the call |
| &key=12345678 | The API key (required for all requests) |
The actual HTTP request and response look as follows (simplified):
GET /index.php?/miniapi/get_case/2&key=12345678 HTTP/1.1 Host: server Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"result": true,
"case": {
"custom_expected": "...",
"custom_preconds": "..",
"custom_steps": "..",
"id": 2,
"priority_id": 4,
"refs": null,
"section_id": 1,
"title": "Print document history and attributes",
"type_id": 2
}
}
Write Request
The following request shows a simple write request to submit a test result:
$ curl -H "Accept: application/json" -d "status_id=1" \ "https://example.testrail.com//index.php?/miniapi/add_result/77756&key=12345678"
The request and response look as follows:
POST /index.php?/miniapi/add_result/2&key=12345678 HTTP/1.1 Host: server Accept: application/json Content-Type: application/x-www-form-urlencoded status_id=1
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"result": true,
"id": 77756,
"url": "http://server/index.php?/tests/view/2"
}
