ZIS bundle: Creating an HTTP request body using jq
The following ZIS bundle includes a Transform action. The Transform action uses jq to create a JSON object. The object uses a reference path as a property key. After the Transform action, the object is passed to the request body of an HTTP request in a ZIS custom action.
The bundle's Transform action is highlighted. When testing the bundle, replace "EXTERNAL_TARGET_URL" with a RequestBin endpoint URL. Replace "INTEGRATION" with your integration key.
{
"name": "Example integration",
"description": "HTTP request body that uses parameter as key",
"zis_template_version": "2019-10-14",
"resources": {
"postToExternalTarget": {
"type": "ZIS::Action::Http",
"properties": {
"name": "postToExternalTarget",
"definition": {
"method": "POST",
"url": "EXTERNAL_TARGET_URL",
"requestBody.$": "$.requestBody"
}
}
},
"NewUserFlow": {
"type": "ZIS::Flow",
"properties": {
"name": "NewUserFlow",
"definition": {
"StartAt": "mockGetCustomField",
"States": {
"mockGetCustomField": {
"Type": "Pass",
"Result": {
"custom_field_key": "favorite_product",
"custom_field_value": "Canyonero"
},
"ResultPath": "$.custom_field",
"Next": "transformCustomFieldObj"
},
"transformCustomFieldObj": {
"Type": "Action",
"ActionName": "zis:common:transform:Jq",
"Parameters": {
"data.$": "$.custom_field",
"expr": "{ (.custom_field_key): .custom_field_value }"
},
"ResultPath": "$.custom_request_body",
"Next": "makeHttpRequest"
},
"makeHttpRequest": {
"Type": "Action",
"ActionName": "zis:INTEGRATION:action:postToExternalTarget",
"Parameters": {
"requestBody.$": "$.custom_request_body"
},
"End": true
}
}
}
}
},
"NewUserSpec": {
"type": "ZIS::JobSpec",
"properties": {
"name": "NewUserSpec",
"event_source": "support",
"event_type": "user.UserCreated",
"flow_name": "zis:INTEGRATION:flow:NewUserFlow"
}
}
}
}
The bundle's Transform action takes the following input from a Pass state:
{
"custom_field_key": "favorite_product",
"custom_field_value": "Canyonero"
}
After applying a jq expression, the Transform action outputs the following object:
{
"favorite_product": "Canyonero"
}
The object is then passed to the requestBody option of the ZIS custom action.