Generate Document Batch
Generates a batch of documents from a set of merge parameters and destinations
Historical API content: This article contains examples from an older API generation and is not validated for the v2.0 contract. Use the migration guide and current API overview.
| Endpoint URL | SDK Method |
|---|---|
https://api.inkit.com/v1/batch (POST) | Batch.create() |
Request properties
| Property | Type | Required | Description |
|---|---|---|---|
template_id | String | Yes | The ID of the template you want to use when generating the batch. |
name | String | No | The name of the batch. While this property is optional, we highly recommend that you use it so that you can better track your batches. |
renders | Object[] | Yes | The set of merge parameters and destinations for the batch. |
renders
renders| Property | Type | Required | Description |
|---|---|---|---|
name | String | No | The name of the document object. |
description | String | No | The description of the document object. |
merge_paremeters | Object | Yes | The key-value pairs you want to use when generating an element of your batch. The data you supply here will replace the fields you have embedded in your document template. |
destinations | Object | No | Details about where and how you want to store the element of the batch. |
Response properties
| Property | Type | Description |
|---|---|---|
id | String | The ID of the batch. |
Example request and response
# Import the Inkit Python package
import inkit
from inkit.exceptions import InkitResponseException
# Import json package
import json
# Replace the string below with your API key
inkit.api_token = "ENTER YOUR API KEY"
try:
# Create a batch of PDF documents from a template
resp = inkit.Batch.create(
# Specify the ID of the template
template_id = "ENTER YOUR TEMPLATE ID",
# Specify the set of documents to generate
renders = [
{
# Specify the data for the merge
"merge_parameters": {"Name": "John"},
# Specify the name of the PDF file
"destinations": {"inkit_storage": {"name": "John"}}
},
{
# Specify the data for the merge
"merge_parameters": {"Name": "Sally"},
# Specify the name of the PDF file
"destinations": {"inkit_storage": {"name": "Sally"}}
},
]
)
# Print the JSON repsonse of the API call
print(json.dumps(resp.data, indent = 3))
except InkitResponseException as err:
# Print any error
print(err.response.data)// Import the Inkit Node.js package
const Inkit = require("inkit");
// Replace the string below with your API key
Inkit.apiToken = "ENTER YOUR API KEY";
// Call batch of PDF renderer
createBatch();
// Create a set of PDF documents from a template
async function createBatch() {
try {
const result = await Inkit.Batch.create({
// Specify the ID of the template
templateId: 'ENTER YOUR TEMPLATE ID',
// Specify the set of documents to generate
renders: [
{
// Specify the data for the merge
merge_parameters: {"Name": "John"},
// Specify the name of the PDF file
destinations: {inkit_storage: {"name": "John"}}
},
{
// Specify the data for the merge
merge_parameters: {"Name": "Sally"},
// Specify the name of the PDF file
destinations: {inkit_storage: {"name": "Sally"}}
},
]
});
// Print the JSON response of the API call
console.log(JSON.stringify(result.data, null, 3));
} catch (error) {
// Print any error
console.error(error.response.status, error.response.statusText);
}
}curl --request POST \
--url https://api.inkit.com/v1/batch \
--header 'Content-Type: application/json' \
--header 'X-Inkit-API-Token: ENTER YOUR API KEY' \
--header 'accept: application/json' \
--data '
{
"renders": [
{
"merge_parameters": {
"Name": "John"
},
"destinations": {
"inkit_storage": {
"name": "John"
}
}
},
{
"merge_parameters": {
"Name": "Sally"
},
"destinations": {
"inkit_storage": {
"name": "Sally"
}
}
}
],
"template_id": "ENTER YOUR TEMPLATE ID"
}
'{
"id": "rb_CDh2Dg57evYHnBp7TbxJt"
}Updated 11 days ago
Did this page help you?