Managing attachments to an object using REST/JSON

When creating or updating an object using the REST/JSON webservices it is sometimes needed to manage the attachments to this object.

In iTop, attachments are managed as a separate objects of class Attachment. An attachment can be created for virtually any other object in iTop, but the configuration of the module itop_attachments determines on which class(es) the attachments are “enabled” in the user interface (i.e. displayed and manageable from the user interface).

Adding an attachment

Using the REST/JSON webservices, attachments can only be related to existing objects (i.e. objects already recorded in the database). Should you want to create a ticket with an attachment, first create the ticket, then create the attachment object.

When creating a new Attachment (using the core/create REST operation) you must fill the following fields:

  • item_class: (string) the class of object to which this attachment will be related (e.g. UserRequest)
  • item_id: (integer) the ID of the object to which this attachment will be related
  • item_org_id: (integer) the ID of the Organization of the object to which this attachment will be related
  • creation_date: (string) the current date and time in MYSQL format (e.g. « 2021-04-30 12 :23 :41 »)
  • contents : an array with 3 elements :
    • data : (string) the base64 encoded binary content of the file
    • filename : (string) the name of the file (for display), e.g. Untitled-1.docx
    • mimetype : (string) the MIME Type of the file, e.g. application/vnd.openxmlformats-officedocument.wordprocessingml.document for a MSWord .docx document.

Deleting an attachment

Attachments can be deleted as any other object in iTop, using the core/delete REST/JSON operation. No action is needed on the target object to which the attachment is related.

Updating an attachment

Even though Attachment objects can be updated using the REST/JSON webservices, the user interface does not allow this operation, so iTop may assume that attachments are immutable (for example when indexing the data). Therefore it is recommended to emulate the behavior of the user interface by deleting the old attachment and creating a new one.

latest/advancedtopics/rest_json_attachment.txt · Last modified: 2024/06/20 17:28 (external edit)
Back to top
Contact us