Fetching Attachments
Introduction
Sometimes attachments details can be provided within another message which require additional API calls to fetch them. We recommend breaking this out using a Poller which will asynchronously fetch the attachments and then push them into Unifi for full tracking. This has a lot of benefits and follows Unifi best practice.
The basic flow is:
Receive a message containing a list of attachment details to fetch from the other system.
Process the message as normal and store the attachment details in the Stage just like any other field.
In the Stage to Target script, loop through the attachments and execute an On-demand asynchronous Poller for each one.
The Poller fetches the attachment and pushes it into Unifi just like any other inbound message. We use a Poller because it has it's own queue management and provides visibility for the transactions.
Unifi processes the message and moves the attachment to the target record. The attachment is also recorded against the bond and the full transaction stack is created.
Setup
This example is based on receiving a message which contains a list of attachments that need to be fetched. You may need to adjust to your specific environment and requirements.
1. Poll Processor
Create a new Poll Processor (we recommend <Integration name> - Get Attachment
). It will fetch a single attachment as required and push it into your integration attachment message.
Name:
<Integration name> - Get Attachment
Integration:
<Integration name>
Active:
true
Run parallel:
true
2. Poller
Create a new Poller (we recommend <Integration name> - Get Attachment
) and set it use the Poll Processor we've just created. For scheduling, set it to run On Demand.
Name:
<Integration name> - Get Attachment
Poll processor:
<Integration name> - Get Attachment
Integration:
<Integration name>
Active:
true
Run:
On Demand
3. Add Attachment Message
You'll need a Message to handle the incoming attachment. You can either use an existing one you already have or create a new one. We recommend calling it AddAttachment
.
Since Unifi will automatically recognise the attachment provided by the Poll Processor, the only mapping you need to configure here is the internal and external reference mapping.
4. Connection Variable
We need to tell the integration which Poller to use for processing the attachments. We do this with the Poller record sys_id. To prevent hard-coding it, we specify it in a connection variable. You'll need to make sure this variable is present on all connections you use.
Description:
The sys_id of the Poller record that we execute to retrieve an attachment.
Key:
get_attachment_poller_id
Value:
<The Poller sys_id>
5. Inbound Message
This section describes what the message that receives the attachment URLs needs to do. You may consider doing this in a new Field and Field Map, or just update the relevant Message Scripts.
Store Attachments Details
When the attachments details are received, they are treated like any other field. Store them in the stage for visibility and later processing.
Process Attachment Details with a Poller
In the Stage to Target script (either Message Script or Field Map), loop through the attachments and execute a Poller.
Test
Now you've configured your inbound message, Poll Processor, Poller and AddAttachment message, it's time to test!