# Complex data types

Up to this point, we have only discussed primitive data types like Strings and Integers. With most APIs, data is represented with more complex structures. These can be broadly classified into JSON Objects and Arrays.

# Mapping complex data in formula mode

Benefits

  • Deal with primitive arrays
  • You may not have prior knowledge of schema
  • Too many fields in a single object to map

# Example

In the following example, we apply tags to Zendesk tickets for associated campaigns, which are tracked in Salesforce. For the purpose of demonstration, we will perform this using a custom action. According to Zendesk API documentation (opens new window), tags should be sent as an array of strings. The payload should look like this:

{
  "ticket": {
    "tags": ["WorkJam", "ProductHour"]
  }
}

Now, this presents a problem for us, because Workato input field mapping exist primary as key/value pairs. This required format is a primitive array of strings. This requires a complex data type (Array of Strings).

To do this, simply toggle the Tags input field to formula mode, and form the required structure. This can be done in a few ways.

First, we can perform a test with a statically defined array of strings. Make sure that the input value observes proper JSON syntax. Invalid values in formula mode will raise design time formula errors.

Static array input Static array input in formula mode

Next, it is a good idea to perform some tests to make sure that the custom action updates the ticket with the new tags as expected. At this point, you can improve the recipe further to update tickets with tags dynamically. Since Zendesk API expect an Array of Strings, we need to retrieve only the Name values from the Campaigns returned from a previous action.

We do this by using the pluck formula, which conveniently returns an array of Name values.

Dynamic array input Dynamic array input in formula mode

Finally, make sure that the right data is sent by checking the job details.

Data structure preserved in formula mode Data structure preserved in formula mode


Last updated: 7/2/2021, 8:43:36 AM