Render Packet
Retrieve a packet with its documents rendered from dynamic data sent in the request body.
This returns the same response as Get Packet Details. The difference is where dynamicData goes. Get Packet Details takes it in the query string, and the API rejects URLs longer than about 8 KB with 414 URI Too Long. Use this endpoint when your dynamic data may not fit in a URL, for example a long list of line items looped with {{#each}}.
The JavaScript library uses this endpoint automatically from version 2.2.0 whenever you pass dynamicData.
Endpoint
POST /api/v1/client/{clientId}/packet/{packetId}/render
Request
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
clientId | string | Yes | Your unique client identifier |
packetId | string | Yes | The ID of the packet to render |
Headers
| Header | Value | Required |
|---|---|---|
accept | application/json | Yes |
content-type | application/json | Yes |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
dynamicData | object | null | No | Values for the variables in the packet's documents. Same shape and limits as dynamicData on Accept: at most 60 KB (61,440 bytes of serialized JSON), 10 levels of nesting and 100 keys in total. Omit it or send null to render without dynamic data |
{
"dynamicData": {
"userName": "John Doe",
"lineItems": [
{ "name": "Annual plan", "price": "$120.00" },
{ "name": "Setup fee", "price": "$25.00" }
]
}
}
Limits and sanitization
dynamicData may be up to 60 KB (61,440 UTF-8 bytes of serialized JSON), well beyond what fits in a URL. It must also have at most 10 levels of nested objects/arrays, at most 100 keys in total (counting the keys of nested objects), and keys of at most 100 characters that don't start with $ or . and aren't __proto__, constructor or prototype. The whole request body may be at most 1 MB.
HTML tags are stripped from every string value before rendering, so values always render as plain text. The rendered documents are sanitized as well.
Response
The response has the same fields as Get Packet Details, with the documents' contents rendered from dynamicData.
Status Code: 200 OK
Error Responses
| Status Code | When |
|---|---|
400 Bad Request | dynamicData is not an object, or breaks one of the limits. The message names the rule, for example dynamicData is too large: 70,112 bytes; the maximum is 61,440 bytes (60 KB), measured as UTF-8 bytes of the serialized JSON |
413 Payload Too Large | The request body is larger than 1 MB |
404 Not Found | The packet was not found for the given client |
Examples
cURL
curl --request POST \
--url 'https://api.toughclicks.com/api/v1/client/477951a5-069b-401f-ab7f-32db486d5741/packet/3646a13b-cbd1-482c-9947-460cb74a71f2/render' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{"dynamicData": {"userName": "John Doe"}}'
Staging Environment
curl --request POST \
--url 'https://api.stage.toughclicks.com/api/v1/client/477951a5-069b-401f-ab7f-32db486d5741/packet/3646a13b-cbd1-482c-9947-460cb74a71f2/render' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{"dynamicData": {"userName": "John Doe"}}'
JavaScript Example
async function renderPacket(clientId, packetId, dynamicData = {}) {
const response = await fetch(
`https://api.toughclicks.com/api/v1/client/${clientId}/packet/${packetId}/render`,
{
method: 'POST',
headers: {
'accept': 'application/json',
'content-type': 'application/json'
},
body: JSON.stringify({ dynamicData })
}
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}
Python Example
import requests
def render_packet(client_id, packet_id, dynamic_data=None):
response = requests.post(
f"https://api.toughclicks.com/api/v1/client/{client_id}/packet/{packet_id}/render",
headers={"accept": "application/json"},
json={"dynamicData": dynamic_data},
)
response.raise_for_status()
return response.json()