Scripted REST Resource
Unifi will automatically generate the Scripted REST Resource to cater for inbound streaming. If using a Resource created on a release prior to v3.0 this will need to be updated manually.
Attachment Resource
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var helper = new x_snd_eb.RestHelper('incident_guides'); // the API name of the Unifi Process
processAttachment(helper.getRequest().getRecord());
helper.processRequest(request, response, 'POST'); // the HTTP method of the resource
/**
* This scripted REST API allows an attachment to be sent into Unifi in a
* similar way to the OOB api/now/attachment REST API, but it processes it
* in Unifi.
*
*/
function processAttachment(target_record) {
var file_name = request.queryParams.file_name;
var reference = request.queryParams.reference;
var mime_type = request.getHeader('Content-Type');
if (!file_name || !reference || !mime_type) return;
var ga = new GlideSysAttachment();
// save the body to an attachment on the request
var attachment_id = ga.writeContentStream(target_record, file_name, mime_type, request.body.dataStream);
// return custom payload for the body to process
helper._getRequestBody = function _getRequestBody() {
return '{\n' +
'"message": { "name": "AddAttachment" },\n' +
'"reference": "' + reference + '",\n' +
'"attachment": "<x-attachment-data sys_id="' + attachment_id + '" />"\n' +
'}';
};
}
})(request, response);Was this helpful?
