POST/projects/{ProjectId}/{EntityCode}/{EntityId}/files

Applies to QAComplete 12.75 SaaS, last modified on April 01, 2021

Adds a new attachment.

Use the operation to add a new attachment (a file, URL or UNC path) to an item (a defect, requirement and so on) in QAComplete.

To replace an existing attachment, use the …/files/{Id} (PUT) operation. To update only the fields of an existing attachment, use the …/files/{Id} (PATCH) operation.

Authentication

Basic authentication using a user’s login and password. See Authentication for details.

Security Rights

The authenticating user must belong to a security group that has the Update privilege for the entity (Defects, Tests and so on) to which you are adding the attachment.

Request Format

To add an attachment to a item, send a POST request with Content-Type multipart/form-data to the following URL:

http://{server}/rest-api/service/api/v1/projects/{ProjectId}/{EntityCode}/{EntityId}/files
URL parameters

ProjectId  :  integer, required

The ID of the project, to which the item belongs.

EntityCode  :  string, required

The type of the item, to which you want to add an attachment. Possible values:

  • Releases
  • Bugs (defects)
  • FunctionalSpecs (requirements)
  • Tests
  • TestSets
  • TestSteps

EntityId  :  integer, required

The ID of the item (a defect, requirement, and so on), to which you want to add an attachment.

Comments  :  string

Comments to the attachment. Can include HTML markup.

Title  :  string (max 255 chars), required

The user-friendly name (title) of the attachment. If omitted, QAComplete will assign the title according to the file name or URL or UNC path.

Body parameters

In the request body, pass the attachment data wrapped as multipart/form-data. Some tools and development libraries let you specify just the file name and construct the request body automatically.

A sample request:

POST http://yourserver.com/rest-api/service/api/v1/projects/11873/Bugs/12/files HTTP/1.1
Host: yourserver.com
Connection: keep-alive
Content-Type: application/json
Accept: application/json
Authorization: Basic am9obkBleGFtcGxlLmNvbTpwQHNzd29yZA==
Content-Length: 717


------WebKitFormBoundaryobxsXCltsQZ5UBfL
Content-Disposition: form-data; name="ProjectId"

11873
------WebKitFormBoundaryobxsXCltsQZ5UBfL
Content-Disposition: form-data; name="EntityCode"

Bugs
------WebKitFormBoundaryobxsXCltsQZ5UBfL
Content-Disposition: form-data; name="EntityId"

12
------WebKitFormBoundaryobxsXCltsQZ5UBfL
Content-Disposition: form-data; name="Comments"

New Comment
------WebKitFormBoundaryobxsXCltsQZ5UBfL
Content-Disposition: form-data; name="Title"

Data
------WebKitFormBoundaryobxsXCltsQZ5UBfL
Content-Disposition: form-data; name="File"; filename="data.txt"
Content-Type: application/octet-stream

... the rest of the data.txt file contents ...
------WebKitFormBoundaryobxsXCltsQZ5UBfL--

A sample request made by using cURL:

curl -i john@example.com:p@ssword -F file=@data.txt -H "Accept: application/json" http://yourserver.com/rest-api/service/api/v1/projects/11873/Bugs/12/files

Response Format

On success, the operation responds with HTTP status code 200. The response is a JSON object with information on the uploaded attachment.

A sample response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 313


{
  "attachment_type_code": "File",
  "file_name": "data.txt",
  "title": "Data",
  "comments": "New Comment",
  "date_created": "2015-08-27T11:48:26.9370000",
  "date_updated": "2015-08-27T11:48:26.9370000",
  "entity_code": "Bugs",
  "entity_id": 12,
  "update_user_id": "24663",
  "user_name": "Smith, John"
}

Error responses

If the operation fails, it returns the appropriate status code and (optionally) the error description in the response body.

If the project with the specified ProjectId does not exist or the authenticating user does not have rights to access the project, the operation returns the Access is denied error.

If an item with the specified EntityCode or EntityId does not exist, the operation returns the File or directory not found error.

QAComplete has a limit on the size of the uploaded file. Please ask your QAComplete server administrator what this limit is. Make sure you do not hit this limit in your API calls.

If the Title you specify for the attachment exceeds the maximum value size, the operation returns an internal server error.

See Also

Files (Attachments) Resources

Highlight search results