Working With Attachments

Nearly all entities support attachments, and the REST API provides multiple read and write operations for managing them.

NOTE:
The REST API depends on the FTP service, which must be properly configured using the PROLIN Smart Client Administration Console.


Retrieve Attachments Associated with an Entity

Attachments can be retrieved using the $expand clause:

GET http://myserver:5181/odata/Problems(7403319703)?$expand=Attachments

Example Response

{
  "@odata.context": "http://myserver:5181/odata/$metadata#Problems(Attachments())/$entity",
  "Uid": 7403319703,
  "Description": "Problem with an attachment",
  "Status": { "Text": "Registered", "Value": 3094610380 },
  "Attachments": [
    {
      "@odata.mediaContentType": "text/plain",
      "@odata.mediaReadLink": "http://myserver:5181/odata/Problems(7403319703)/Attachments(7403319706)/$value",
      "Name": "MyAttachment2.txt",
      "FileName": "C:\\SomePath\\SubPath\\MyAttachment2.txt",
      "Uid": 7403319706
    }
  ]
}

Alternatively, you can retrieve attachments via a navigation path:

GET http://myserver:5181/odata/Problems(281487403319703)/Attachments

OData Properties

Property Description
@odata.mediaReadLink URI to read the binary file stream associated with the attachment.
@odata.mediaContentType MIME type representing the format of the attached document.

Downloading Attachment Content

Use the @odata.mediaReadLink property to download the attachment file:

GET http://myserver:5181/odata/Problems(7403319703)/Attachments(7403319706)/$value

Notes: - The first key (7403319703) identifies the parent entity.
- The second key (7403319706) identifies the attached file.
- The trailing $value is required to fetch the file stream itself.


Adding a New Attachment

Add an attachment via a multipart/form-data HTTP POST request:

POST http://myserver:5181/odata/Problems(7403319703)/Attachments  HTTP/1.1
Authorization: Bearer ...
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
Content-Length: 3127

---------------------------acebdf13572468
Content-Disposition: form-data; name="alt-file-name"; filename="myfile.txt"
Content-Type: text/plain

<<FILE CONTENT HERE>>
---------------------------acebdf13572468--

Example Successful Response

{
  "Name": "alt-file-name",
  "FileName": "myfile.txt",
  "DateCreated": "2019-07-05T13:50:26.7247883Z",
  "Uid": 281561403300546
}

If an attachment with the same name already exists:

{
  "error": {
    "message": "An attachment named 'alt-file-name' already exists. A unique name is required."
  }
}

HTTP Status: 409 Conflict


Conflict Resolution

You can modify conflict behavior using the Prefer header.
When the server applies a preference, it returns a Preference-Applied header in its response.
Refer to the conflict-resolution section for detailed behavior.


Deleting an Attachment

Deleting attachments follows the same pattern as deleting entities, but with two keys:

DELETE http://myserver:5181/odata/Problems(7403319703)/Attachments(7403319706)

Attachments Associated with History Lines

You can manage attachments related to history lines using a similar URI structure:

GET /odata/Problems(7403319703)/HistoryLines(7421290120)/Attachments(7403319706)/$value

Note the extra HistoryLines segment, which indicates the navigation path for the specific attachment.


Summary

Operation Method Example
Get attachments GET /Problems(7403319703)?$expand=Attachments
Download attachment GET /Attachments(7403319706)/$value
Add attachment POST /Problems(7403319703)/Attachments
Delete attachment DELETE /Problems(7403319703)/Attachments(7403319706)
History line attachment GET /HistoryLines(...)/Attachments(...)/$value
Back to top