Batch Generate PDFs

Create up to 50 PDFs with a single batch request

HTTP Request

POST https://app.formapi.io/api/v1/submissions/batch

Authentication

You must send an Authorization header with the value Basic followed by base 64 encoded token_id:token_secret.

For example: Authorization: Basic dG9rZW5faWQ6dG9rZW5fc2VjcmV0Cg==

See the Authentication documentation for more information.

Parameters

The request body must be a JSON object with the following keys:

  • template_id (object, optional): The default template ID for submissions. You can override this for each submission.
  • test (boolean, optional) (default: false): The default test value for submissions. true to generate a test PDF (watermarked), false for a live PDF. You can override this for each submission.
  • metadata (object, optional): Any additional data, such as a user id. This will be saved on the submission batch job.
  • submissions (array): An array of submission objects.

The submissions property must be a JSON array of objects. Each object in the array must have the following keys:

  • template_id (string, optional): The template ID for this submission. If not provided, uses the template_id from the root object.
  • data (object): Data to fill in the fields. Must match the template schema.
  • metadata (object, optional): Any additional data, such as a user id. metadata will be included in webhook requests.
  • test (boolean, optional): true to generate a test PDF, false for a live PDF. Test PDFs are free, but watermarked. Note: A test API token can only be used to generate test PDFs.

Example Code

// This is a live example that you can run with Node

var FormAPI = require("@formapi/formapi");

var config = new FormAPI.Configuration();
config.apiTokenId = "yRaaR9JmTPtGX7EN";
config.apiTokenSecret = "IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec";
client = new FormAPI.Client(config);

var templateId = "6zz3dYRYM67fxMXA";
var submissionData = [
  {
    test: true,
    data: {
      first_name: "John",
      last_name: "Smith",
      favorite_color: "Blue"
    },
    metadata: {
      user_id: 123
    }
  },
  {
    test: true,
    data: {
      first_name: "Jane",
      last_name: "Doe",
      favorite_color: "Red"
    }
  }
];
client.batchGeneratePDFs(templateId, submissionData, function(
  error,
  responses
) {
  if (error) throw error;
  console.log(responses);
});
# This is a live example that you can run in IRB.

require 'form_api'

ENV['FORMAPI_TOKEN_ID'] = "yRaaR9JmTPtGX7EN"
ENV['FORMAPI_TOKEN_SECRET'] = "IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec"
TEMPLATE_ID = "6zz3dYRYM67fxMXA"

FormAPI.configure do |c|
  c.username  = ENV['FORMAPI_TOKEN_ID']
  c.password  = ENV['FORMAPI_TOKEN_SECRET']
end

formapi = FormAPI::Client.new

responses = formapi.batch_generate_pdf(TEMPLATE_ID,
  create_submission_batch_body: [
    {
      test: true,
      data: {
        first_name: 'John',
        last_name: 'Smith',
        favorite_color: 'Blue',
      },
      metadata: {
        user_id: 123
      }
    },
    {
      test: true,
      data: {
        first_name: 'Jane',
        last_name: 'Doe',
        favorite_color: 'Red',
      },
    }
  ]
)
# This is a live example that you can run in the Python interpreter
import form_api

client = form_api.Client()
client.api_client.configuration.username = "yRaaR9JmTPtGX7EN"
client.api_client.configuration.password = "IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec"

template_id = '6zz3dYRYM67fxMXA'

response = client.batch_generate_pdfs({
    'template_id': template_id,
    'metadata': { 'batch_user_id': 123 },
    'test': True,
    'submissions': [
        {
            'data': {
                "first_name": "John",
                "last_name": "Smith",
                "favorite_color": "Green",
            },
            "metadata": { "user_id": 123 }
        },
        {
            'data': {
                "first_name": "Jane",
                "last_name": "Doe",
                "favorite_color": "Blue",
            },
            "metadata": { "user_id": 456 }
        }
    ]}, wait=True)

print(response.status)  # => 'success'
print(response.submission_batch.state) # => 'processed'
print(response.submission_batch.pending_count) # => 0
print(response.submissions)

If the wait argument is omitted or True, the method will wait for the batch to finish processing.

You can also pass wait=False to return immediately, and you will receive a pending batch job. You can call get_submission_batch(response.submission_batch.id) to fetch the current status of the batch.

If you want to batch generate multiple PDFs and combine them into a single operation, you can do that with the batch_generate_and_combine_pdfs method. This takes the same arguments as batch_generate_pdfs, and returns a "combined submission" response.

<?php
// This is a live example that you can run in the PHP interactive shell (php -a)
$formapi = new FormAPI\Client();
$formapi->getConfig()->setUsername("yRaaR9JmTPtGX7EN");
$formapi->getConfig()->setPassword("IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec");

$template_id = '6zz3dYRYM67fxMXA';

$create_submission_batch_body = json_encode(array(
    [
      'data' => [
        "first_name" => 'John',
        "last_name" => 'Smith',
        "favorite_color" => 'Green'
      ]
    ],
    [
      'data' => [
        "first_name" => 'Jane',
        "last_name" => 'Doe',
        "favorite_color" => 'Blue'
      ]
    ]
  ));

$responses = $formapi->batchGeneratePDFs($template_id, $create_submission_batch_body);
print_r($responses);
using System;
using System.Diagnostics;
using FormApi.Client.Api;
using FormApi.Client.Client;
using FormApi.Client.Model;

namespace Example
{
    public class FormAPIExample
    {
        public void main()
        {
          Configuration.Default.Username = "yRaaR9JmTPtGX7EN";
          Configuration.Default.Password = "IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec";

          var apiInstance = new PDFApi();
          string templateId = "tpl_000000000000000001";
          var createSubmissionData = new List<CreateSubmissionData>(
            new CreateSubmissionData[] {
              new CreateSubmissionData(
                false,  // true to generate a test PDF (watermarked)
                new {
                  title = "Test PDF",
                  description = "This PDF is great!"
                }
              ),
              new CreateSubmissionData(
                false,  // true to generate a test PDF (watermarked)
                new {
                  title = "Test PDF 2",
                  description = "This PDF is also great!"
                }
              )
            }
          );

          List<CreateSubmissionResponse> response = apiInstance.BatchGeneratePDFs(templateId, createSubmissionData);
          Debug.WriteLine(response);
        }
    }
}

The following example waits for the PDF to be processed, then prints the download URL.

# This is a live example that you can run in your console.

export API_TOKEN_ID="yRaaR9JmTPtGX7EN"
export API_TOKEN_SECRET="IB3TRkSdm4f2BdtU_D3YgxjdMB7l-r2fOgvxD1Yzwec"
export TEMPLATE_ID="6zz3dYRYM67fxMXA"

curl -s "https://app.formapi.io/api/v1/templates/$TEMPLATE_ID/submissions/batch" \
  -u "$API_TOKEN_ID:$API_TOKEN_SECRET" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '[{"data":{"first_name": "John", "last_name": "Smith", "favorite_color": "Blue"}, "metadata": { "user_id": 123 }}]'

results matching ""

    No results matching ""