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
determines on which class(es) the attachments are “enabled” in the
user interface (i.e. displayed and manageable from the user
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
item_class: (string) the class of object to which this attachment will be related (e.g.
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.
mimetype : (string) the MIME Type of the file, e.g.
application/vnd.openxmlformats-officedocument.wordprocessingml.documentfor a MSWord .docx document.
Deleting an attachment
Attachments can be deleted as any other object in iTop, using
core/delete REST/JSON operation. No action is
needed on the target object to which the attachment is
Updating an attachment
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.