Generate a document from a template

Optimize your document generation workflows by using templates and dynamic content merging

In this topic, you will discover how to generate a document from a predefined template. Thus, this grants you the ability to utilize document templates to streamline and optimize your document generation workflows.

At the end of this guide, you will have generated a sample document from a template. But more importantly, you will feel ready to implement templates for standardized documents in your organization.

Prerequisites:

  • You know how to send a render create request
  • You have a mock request tool like Postman or Insomnia at hand
  • You know about templates and how they work

Read more about:

Getting ready

Before you can generate a document with a template, you must first complete a few preliminary steps. First, you will want to create a template in the Inkit web environment. Second, you will need to save its ID and have it ready for later in this guide.

While this is not an in-depth guide about creating templates, you may use the visual demonstration here for assistance. We have created a template with the key "replaceMe" inside the document.

Be sure to surround any key with the characters %% on both sides.

  • Else, learn how to create a template here (coming soon)

Next, you’ll want to have an API key with the Renders.create permission. Without it, you won’t be able to generate your document.

Make sure you have your to be merged content organized into a list of key : value pairs. You will need them in your create request.

As a quick reminder, the keys are the markers you include in your template. The Inkit Render API will replace them with the correct corresponding value.

Creating a document from a template

If you have your template ID at hand and your API key ready, then you can continue by following these next steps. Now then, it is time to generate a document from a template.

  1. Open your API request testing tool and create a new post request. We are using Insomnia.

  2. Include your API key in the request headers under the variable name X-Inkit-Token

  1. However, unlike standard create requests, you do now not have to include the HTML source, unit, width, and height parameters.

  2. In your JSON body, include the template ID you would like to use under the body parameter “templateid”. Template IDs are formatted as "tmpl" + a string of characters.

{
         "template_id": "your template ID"
}
  1. Now also add the key-value pairs you created earlier in this guide. Add them to your request under boy parameter “merge_parameters”
{
         "template_id": "your template ID",
         "merge_parameters": {
          "replaceMe": "Hello World"
     }
}

Note: You can add as many merge_parameters as you like. Just make sure that the keys can be found in your template.

If you wish to add more key-value pairs to your merge_parameters JSON object, you would do so this way:

"merge_parameters": {

          "replaceMe": "Hello World",

          "newKey": "New Value",

          "newKey-1": "New Value",

          "newKey-2": "New Value",

          "newKey-3": "New Value"

     }
  1. Send your request to the endpoint: https://api.inkit.com/v1/render

You should now see a 201 successful response code. If so, then you have created a document through a template. You should now be able to implement templates into your technical workflows and processes.

Optional: Pull your document, you should see the key replaced with the value you designated


Did this page help you?