Documentation for version v72
Pack
Description
The Pack pipe marshals JSON or XML and writes the result to $in.body as a byte array. It only makes sense to use it in conjunction with an http pipe.
Structure
| Field | Type of value | Example | Required | Description |
|---|---|---|---|---|
| id | number | 10 | yes | Pipe's ID |
| type | string | "pack" | yes | Type of a pipe |
| params | PackParamsObject | no | Type-specific parameters | |
| outs | OutsObject | no | Pipe's outputs |
| PackParamsObjectt | ||||||
|---|---|---|---|---|---|---|
| Field | Type | Example | Reqiered | Default | Description | |
| type | string | "JSON" | no | "JSON" | Format.Possible values:- JSON -XML | Custom prefix for log message. |
| template | object | {} | yes | - | JSON representation of the resulting JSON or XML. | |
Errors
- params.type is not valid.
- Error processing *params.template - the template is not correct or the field was not found.
Examples
- Example of a JSON packer.
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:
{
"acceptUrl": "http://exmaple.com/accept_url",
"backgroundColor": "#ffffff",
"backgroundImage": "http://exmaple.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://exmaple.com/merchantDomain",
"merchantLogoPng": "http://exmaple.com/merchantLogoPng",
"merchantLogoSvg": "http://exmaple.com/merchantLogoSvg",
"merchantName": "merchantName",
"offerEnd": "2021-08-09T18:31:42",
"partnerCampaignId": 101,
"blockIds": ["adfadf", "dadasdasdas", "aaaaaa"],
"segments": ["aaaa", "bbbb"]
"test_obj": {
"field1": 1,
"field2": ""
}
}
- Example of an XML packer.
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"
},
{
"-channel": "PUSH",
"-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:
<?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" />
<address channel="PUSH" 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>