adding an attachment while creating an incident through REST API

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 06:04 AM
Hi Everyone!! Can anyone please let me know how can we add an attachment(doc,docx,zip,pdf,txt,xls,xlsx,ppt,pptx,jpg,jpeg) while creating an incident through REST API??
I found attachment API through which it can be done. But create Incident and uploading attachment should be done through single REST call not through two different APIs.
Anyone help on this will be appreciated ?? How can this be achieved??
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 06:56 AM
Hi swathi padighar,
These are two fundamentally different activities, which take very different data types. The Table API (for creating an Incident) takes JSON or XML, while the Attachment API takes either binary or a multipart-form data. We don't have a single endpoint for creating an Incident and attaching something to it.
If you want to be very clever, you can write your own middleware that can accept a single request to create an incident *and* add an attachment to it. In that case, you can accept whatever incoming types you like, parse them how you see fit, then have that middleware make the two API calls.
Alternatively, you could write a Processor which does the same thing- accepts a POSTed form which contains both the attachment data and the Incident data as fielded values, and then use GlideRecord and the SysAttachment API to create the record and attach to it.
All of this seems like a lot of work, prone to breaking (in the middleware case) or obsolescence (in the Processor) case, when you could simply make 2 API calls that will continue to be supported for the foreseeable future.
Thanks
Cory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 07:07 AM
Hi Cory,
You forgot that customers can write their own scripted REST endpoints, and that those can accept data in either JSON or XML format. Attachments that were formatted as BASE64-encoded text could be fielded as data in a JSON or XML document, along with all the fields for an Incident. From there, the Scripted REST script could:
- Parse the data
- Do a GlideRecord insert of the fielded Incident data
- Create a new GlideSysAttachment object
- Use GlideSysAttachment's writeBase64 method to create the Attachment with the encoded Base64 data and attach it to the Incident.
But still, you're right: 2 API calls to supported APIs makes more sense and seems a lot easier.
Thanks,
Cory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 07:10 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2016 12:04 AM
Hi Cory!! Thanks for the suggestion!!