Pack
Pack is a Pipe for packing data into JSON or XML. The result is written to $in.body as a byte array, ready to be passed to the HTTP Request pipe.
Parameters
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
type | string | No | JSON | Packing format: JSON or XML |
template | object | Yes | — | Structure of the resulting JSON or XML. Values support templating |
caution
XML is described in JSON format using the notation of the clbanning/mxj library:
- Element attributes are written with a
-prefix (e.g.,"-type": "MESSAGE") - Text content is written as
"#text" - JSON arrays are converted into repeating XML elements
Possible Errors
- Invalid value of
params.type - Error processing
params.template— incorrect template or field not found
Examples
JSON
Pipe:
{
"id": 6,
"type": "pack",
"params": {
"type": "JSON",
"template": {
"acceptUrl": "$template.acceptUrl",
"backgroundColor": "$template.background_color",
"backgroundImage": "$template.background_Image",
"campaignEnd": "$camp_schedule.stop_time",
"feeType": "fix",
"campaignFee": 0,
"campaignStart": "$camp_schedule.start_time",
"campaignType": "$campaign.campaignType",
"categoryId": "$#campaign.category.category",
"conditions": "$template.conditions",
"description": "$template.description",
"discountAmount": "$#template.discountAmount",
"discountCurrency": "$#template.discountCurrency",
"discountType": "$template.discountType",
"fontColor": "$template.font_color",
"merchantDomain": "$account.merchantDomain",
"merchantLogoPng": "$account.merchantLogoPng",
"merchantLogoSvg": "$account.merchantLogoSvg",
"merchantName": "$account.merchantName",
"offerEnd": "$camp_schedule.stop_time",
"partnerCampaignId": "$#origin.c_id",
"blockIds": "$#campaign.blockIds",
"$$campaign.segment[segments]": ["[$]id"],
"test_obj": {
"field1": 1,
"field2": ""
}
}
},
"outs": {
"success": 7,
"error": 8
}
}
Result in $in.body:
{
"acceptUrl": "http://example.com/accept_url",
"backgroundColor": "#ffffff",
"backgroundImage": "http://example.com/background_image",
"campaignEnd": "2021-08-09T18:31:42",
"feeType": "fix",
"campaignFee": 0,
"campaignStart": "2021-05-09T15:22:00",
"campaignType": "test",
"categoryId": 50,
"conditions": "test_condition",
"description": "",
"discountAmount": 155,
"discountCurrency": 482,
"discountType": "RUB",
"fontColor": "#ffffff",
"merchantDomain": "http://example.com/merchantDomain",
"merchantLogoPng": "http://example.com/merchantLogoPng",
"merchantLogoSvg": "http://example.com/merchantLogoSvg",
"merchantName": "merchantName",
"offerEnd": "2021-08-09T18:31:42",
"partnerCampaignId": 101,
"blockIds": ["adfadf", "dadasdasdas", "aaaaaa"],
"segments": ["aaaa", "bbbb"],
"test_obj": {
"field1": 1,
"field2": ""
}
}
XML
Pipe:
{
"id": 106,
"type": "pack",
"params": {
"type": "XML",
"template": {
"event": {
"-cancel": "false",
"-type": "MESSAGE",
"-xmlns": "http://example.com/event.xsd",
"recipients": {
"recipient": {
"addresses": {
"address": [
{
"-channel": "APL",
"-type": "CLIENT_ID",
"-value": "$subscription.id"
}
]
}
}
},
"templates": {
"template": [
{
"#text": "$template.title",
"-channel": "APL",
"-type": "TITLE"
},
{
"#text": "$template.body",
"-channel": "APL",
"-type": "BODY"
},
{
"#text": "$template.push_body",
"-channel": "PUSH",
"-type": "BODY"
}
]
}
}
}
},
"outs": {
"success": 108,
"error": 109
}
}
Result in $in.body:
<?xml version="1.0" encoding="UTF-8"?>
<event xmlns="http://example.com/event.xsd" cancel="false" type="MESSAGE">
<recipients>
<recipient>
<addresses>
<address channel="APL" type="CLIENT_ID" value="aaaaaaaa" />
</addresses>
</recipient>
</recipients>
<templates>
<template channel="APL" type="TITLE">some title</template>
<template channel="APL" type="BODY">some body</template>
<template channel="PUSH" type="BODY">some push body</template>
</templates>
</event>