Extracting Attachments

circle-info

We strongly recommend streaming attachments where possible.

Streaming allows attachments to be received directly by Unifi without embedding them in the payload, bypassing the need for extraction. It supports binary file transfer and attachment sizes of up to 50MB, subject to instance and integration configuration.

Inbound attachment streaming is available for all integrations created in Unifi 3.0 and later.

For more information on configuring inbound streaming, please see our How to Handle Attachments guide.

Overview

Inbound attachments can be extracted from the inbound payload and saved as ServiceNow attachments before the payload is stored. This is strongly recommended, as it avoids storing large Base64-encoded attachment data directly on the HTTP Request record.

When extracting attachments:

  1. Attachment data is detected in the inbound payload

  2. The attachment is saved as a ServiceNow attachment

  3. The attachment data in the payload is replaced with an attachment reference in the form:

<x-attachment-data sys_id="..."></x-attachment-data>

Unifi will then automatically:

  • Collect the attachment sys_id values from the rewritten payload

  • Create Bonded Attachments for each extracted attachment

  • Move the attachments to the target record during processing


Enable Attachment Extraction

Attachment extraction is enabled via Message → Inbound → Settings → Extract attachments. When enabled, Unifi executes the Extract attachments script against the raw inbound payload, before any parsing, mapping, or staging occurs.

The script is expected to extract any embedded attachment data, persist it as a ServiceNow attachment, and rewrite the payload by replacing the embedded data with a Unifi attachment pointer in the form <x-attachment-data sys_id="..." />.

Unifi then continues processing using the rewritten payload, automatically detecting attachment pointers, creating bonded attachments, and moving the extracted attachments to the resolved target record.


Behavioural Requirements

The extract logic must:

  • Locate attachment data in the inbound payload

  • Save attachment content as a ServiceNow attachment

  • Replace the original attachment data with an attachment pointer

  • Return the rewritten payload to Unifi to be saved as the HTTP Request payload

Unifi relies on the <x-attachment-data sys_id="..."/> pointer to identify and process extracted attachments.

Extraction Pattern

Attachments must be located and the attachment content replaced within the payload structure. The extraction workflow remains the same regardless of type (JSON or XML):

  1. Parse the inbound payload into a structure you can traverse

  2. Locate each embedded attachment (e.g. an Attachment node/object)

  3. Extract attachment metadata and content (for example file name, MIME type, Base64 data)

  4. Save the attachment as a ServiceNow attachment

  5. Replace the embedded attachment content in the payload with an attachment pointer:


JSON Example

This example demonstrates extracting attachments from a JSON payload, saving the attachment data, and replacing it in the payload with an attachment reference.


XML Example

This example demonstrates extracting attachments from an XML (SOAP) payload, saving the attachment data, and replacing the attachment data element with an attachment reference.

Last updated

Was this helpful?