Add an Attachment

Summary

To add an attachment, perform the following steps:

1. Upload the file you want to attach to the server as a multi-request to /flex/upload/document/genericattachment. Use a cURL command or Postman.

2. You will get the file name and temporary location in the JSON format.

3. Call the createAttachment API (/flex/services/rest/latest/attachment/list). Enter the name and temporary location of the uploaded file.

4. Your file is added as an attachment. Click Attachments to know more about the supported file formats.

To Upload the file to the server using a cURL command:

1. Download cURL. Extract the zip file.

2. Open the command prompt. Navigate to the src folder containing the curl.exe executable.

2193784849.png

3. Run the following cURL command:

curl --request POST \

--url '<https://<IP>/flex/upload/document/genericattachment'> \

--header 'Authorization: Bearer <ZEPHYR_API_TOKEN>' \

--header 'content-type: multipart/form-data'\

--form 'data=@<file path>'

<file path> - the location of the file you want to upload

<IP> - the server IP

<ZEPHYR_API_TOKEN> - your zephyr API token

Example: curl --request POST \

--url 'https://qademo.yourzephyr.com/flex/upload/document/genericattachment' \

--header 'Authorization: Bearer 23a579b6ad61afd7e9cf4c56c006adfbb2af30c3' \

--header 'content-type: multipart/form-data'\

--form 'data=@/Users/john.smith/pdfFile.pdf'

4. The above-mentioned command returns the temporary location of the uploaded file in the JSON format.

3602448393.png

Example: file":"/opt/zephyr/nodedata/temp/1486648889167_29/js1.pdf"

To upload the file to the server via Postman:

  1. Launch Postman.

    Method : POST

    URI : http://<server-ip>/flex/upload/document/genericattachment

    (Example: https://qademo.yourzephyr.com/flex/ upload/document/genericattachment)

  2. On the Body tab, select form-data.

  3. Specify key as data and for the value select file from the dropdown and choose the file you want to upload.

    Warning

    Do not provide any headers.

2193784868.png

4. In the Authorization tab provide the Bearer token.

3601956875.png

5. When you click SEND, you get the location of the uploaded file in the JSON format.

2193784874.png

To attach the uploaded file:

1. In the createAttachment API request provide the file path in the tempPath attribute and send a request.

Method : POST

URI : http://<server-ip>/flex/services/rest/latest/attachment/list

[{
   "name": "js1.pdf",
   "itemId": 553,
   "itemType": "testcase",
   "contentType": "application/octet-stream",
   "tempPath": "%2F1522663583732_106%2Fjs1.pdf"
}]
2193784862.png

On success (HTTP/1.1 200 OK) the file is attached.

Publication date: