As REST data received from a web service is returned in structured form, it's often useful to map a REST response into an advanced variable type.
This article provides details on how to use Interact advanced variable types when defining REST responses, including:
- Custom Types. Multiple variable types that use a set of fields relating to a specific object. For example, a Custom Type for a Customer object might be made up of the fields First Name, Last Name, Account ID, Phone Number, Contact Date, etc.
- Collections. A type of User variable that contains a list of items. Simple collections contain values of the same data type (e.g., a list of numbers). Object collections contain a list of items (objects) that are each made up of a set of fields.
- Dynamic Variables. A variable that consists of a JSON object, enabling its content to be changed anytime to suit the current data needs of a Flow.
For details on using simple variable types in REST responses, click here.
Mapping to a Custom Type
To map the REST response to an existing Custom Type, just select the relevant Custom Type from the Response panel using the Variable Type dropdown, as shown below.
Note: Be sure to verify that the existing Custom Type fields exactly match the data that will be returned by the REST response. If need you can manually map the fields, as detailed here.
To map the response to a newly-created Custom Type, perform the following procedure:
- In the Response panel, click the Variable Type dropdown list, scroll to the bottom, and select New custom type. The Create button appears.
- Click Create.
The Create Custom variable response popup opens.
- At the left side of the popup, click Get Response. The Integration Point response is parsed, and its fields are displayed.
- In the Name for new Custom Type textbox, enter the relevant name.
- For each field, in the Alias column, change the value to a friendly name of your choice. When necessary, select the correct variable type from the Type dropdown list. (By default, all fields are assigned a Text type.)
- Customize the list of fields as required:
- To delete an unnecessary field, click the Remove link in the relevant row. In runtime, the field will be ignored.
- To add a field that will be required later (e.g., in a different environment), in the last row of the grid, enter the path, key and alias in the appropriate fields, and select the relevant type. Then, click Add.
- At the bottom of the popup, click Create. The new Custom Type is saved in the system.
Manually Mapping Fields in a Custom Type
You can manually edit the mapping between response elements and the fields in an existing Custom Type. This is useful when the necessary keys are not at the root of the response, or when you are working with a Custom Type that is used with slightly different Integration Point responses. The following response is an example of a nested object whose fields (city, street, and zip) would require manual mapping.
- In the Response panel, click the Variable Type dropdown list, and select the related Custom Type. Then, click Details.
The Create custom variable response popup opens. The Key, Alias, and Type columns are read-only.
- For each relevant field, in the Path column, modify the path as required.
- At the right upper corner of the popup, click Save. The popup closes, and changes are saved in the system.
Mapping to a Collection
- In the Response panel, from the Variable Type dropdown list, select Collection.
- Click on the field to the right of the words of type, and from the options menu, select the variable type created to hold the set of values.
- In the Variable Name field, enter a name for the variable that will store the Collection.
Mapping to a Dynamic Variable
This procedure shows how to map a REST response to a dynamic variable JSON object.
- Invoke the wizard and in the REST panel, using a URL that returns a JSON formatted object.
- Complete all required parameters in the REST and Request panels.
- From the Response panel, select Dynamic from the Variable Type dropdown menu. Note that the XPath field will change to grey in order to prevent input:
- In the Variable Name field, enter a name for the dynamic variable that will contain the entire REST response.
- Complete the wizard to finish creating the new Integration Point.
You can parse the JSON object IP response to extract the specific data that you need for the Flow. For details on using dynamic variables in Interact, refer to Using Dynamic Variables.