API: Attachments

Use the following API methods to upload, retrieve and delete attachments.

Note: The following headers must be used when uploading attachments via the TestRail API using POST requests:

Content-Type multipart/form-data
The attachment should be submitted as form-data in the body of the request. Please review our Accessing the API documentation or TestRail's bindings for examples of submitting an attachment.

add_attachment_to_result

Please note the ability to edit test results must be enabled under 'Site Settings' in order for add_attachment_to_result endpoints to work.

Adds attachment to a result based on the result ID. The maximum allowable upload size is set to 256mb.

POST index.php?/api/v2/add_attachment_to_result/:result_id

:result_id The ID of the result the attachment should be added to

See Results API documentation for details of how to obtain :result_id's.

Response Content

Please see below for a typical response:

{
    "attachment_id": 443
}

The following system fields are always included in the response:

Name Type Description
attachment_id int The ID of the attachment uploaded to TestRail

Response Codes

200 | Success, the attachment ID is returned in the response
400 | POST request not formatted properly or invalid result ID
403 | No access to the project

add_attachment_to_result_for_case

Adds attachment to a result based on a combination of result and test case IDs.

POST index.php?/api/v2/add_attachment_to_result_for_case/result_id:/:case_id
:case_id | The ID of the test case

The method returns the same response format as add_attachment_to_result.

Response Codes

200 | Success, the attachment ID is returned in the response
400 | POST request not formatted properly or Invalid result ID or test case ID
403 | No access to the project

get_attachments_for_case

Returns a list of attachments for a test case.

GET index.php?/api/v2/get_attachments_for_case/:case_id

Response Content

Please see below for a typical response:

[
    {
        "id": 444,
        "name": "What-Testers-Should-Be-Automating.jpg",
        "filename": "444.what_testers_should_be_automating.jpg",
        "size": 166994,
        "created_on": 1554737184,
        "project_id": 14,
        "case_id": 3414,
        "test_change_id": 17899,
        "user_id": 10
    }
]

The following system fields are always included in the response:

Name Type Description
id int The unique ID for the attachment
name string Name of the attachment
filename string The filename of the attachment
Size int Size of the attachment in bytes
created_on timestamp The time/date the attachment was uploaded
project_id int The ID of the project the attachment was uploaded against
case_id int The ID of the case the attachment belongs to
test_change_id int The test change ID to which the attachment belongs to
user_id int The ID of the user who uploaded the attachment

Response Codes

200 | Success, an array of attachment details is returned in the response
400 | Invalid test case ID
403 | No access to the project

get_attachments_for_test

Returns a list of attachments for test results.

GET index.php?/api/v2/get_attachments_for_test/:test_id

The method returns the same response format as get_attachments_for_case.

Response Codes

200 | Success, an array of attachment details is returned in the response
400 | Invalid test ID
403 | No access to the project

get_attachment

Returns the requested attachment identified by :attachment_id.

GET index.php?/api/v2/get_attachment/:attachment_id

Response Codes

200 | Success, the attachment is returned in the body of the response
400 | Invalid attachment ID
403 | No access to the project

delete_attachment

Deletes the specified attachment identified by :attachment_id.

POST index.php?/api/v2/delete_attachment/:attachment_id

Response Content

A successful delete_attachment POST will return an empty response body with a 200 response code.

Response Codes

200 | Success, the attachment was deleted
400 | Invalid attachment ID
403 | No access to the project