Combine PDFs

Merges multiple submissions into a single PDF.

HTTP Request

POST https://app.formapi.io/api/v1/combine_submissions

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:

  • submission_ids (array): An array of processed submission IDs. (PDFs will be merged in the same order.)
  • metadata (object, optional): Any additional data, such as a user id. metadata will be included in webhook requests.

Note: This feature is free to use, but the source PDFs will count towards your monthly usage.

Example Code

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

var config = new FormAPI.Configuration();
config.apiTokenId = "FORMAPI_TOKEN_ID";
config.apiTokenSecret = "FORMAPI_TOKEN_SECRET";
client = new FormAPI.Client(config);

var opts = {
  submission_ids: ["sub_000000000000000001", "sub_000000000000000002"]
};
client.combineSubmissions(opts, function(error, combinedSubmission) {
  if (error) throw error;
  console.log(combinedSubmission);
});
require 'form_api'

ENV['FORMAPI_TOKEN_ID'] = "YOUR_API_TOKEN_ID"
ENV['FORMAPI_TOKEN_SECRET'] = "YOUR_API_TOKEN_SECRET"

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

formapi = FormAPI::Client.new

response = formapi.combine_submissions(
  submission_ids: ["SUBMISSION_1_ID", "SUBMISSION_2_ID", ... ],
  metadata: {
    user_id: 123
  }
)

puts "Download your combined PDF at: #{response.combined_submission.download_url}"
# 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 = "FORMAPI_TOKEN_ID"
client.api_client.configuration.password = "FORMAPI_TOKEN_SECRET"

combined_submission = client.combine_submissions({
  "submission_ids": ["SUBMISSION_1_ID", "SUBMISSION_2_ID", ... ],
  "metadata": {
    "user_id": 123,
  }
})

print("Download your combined PDF at: %s" % combined_submission.download_url)
<?php
// This is a live example that you can run in the PHP interactive shell (php -a)
$formapi = new FormAPI\Client();
$formapi->getConfig()->setUsername('YOUR_API_TOKEN_ID');
$formapi->getConfig()->setPassword('YOUR_API_TOKEN_SECRET');

$params = new FormAPI\Model\CreateCombinedSubmissionBody([
  "test" => false,
  "submission_ids" => [ "SUBMISSION_1_ID", "SUBMISSION_2_ID", ... ],
  "metadata" => [ "key" => "value" ]
])

$response = $formapi->combineSubmissions($params);
echo $response;

echo "Download your combined PDF at: " . $response->getCombinedSubmission()->getDownloadUrl();
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();
          var combinedSubmissionData = new CombinedSubmissionData(
            false,
            new List<string>(new string[] {
              "sub_000000000000000001",
              "sub_000000000000000002"
            })
          );
          var combinedSubmission = apiInstance.CombineSubmissions(combinedSubmissionData);
          Debug.WriteLine(combinedSubmission);

          // The job will now be in the "pending" state until it is processed.
          // You may want to call GetCombinedSubmission once per second until
          // the state changes to "processed".
          // Alternatively, you can set up a webhook notification.
        }
    }
}

The following example waits for the merged 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="YOUR_API_TOKEN_ID"
export API_TOKEN_SECRET="YOUR_API_TOKEN_SECRET"

combine_submissions() {
  curl -s "https://app.formapi.io/api/v1/combine_submissions" \
    -u "$API_TOKEN_ID:$API_TOKEN_SECRET" \
    -H "Content-Type: application/json" \
    -X POST \
    -d '{"submission_ids":["SUBMISSION_1_ID", "SUBMISSION_2_ID"], "metadata": { "user_id": 123 }}'
}

get_combined_submission() {
  curl -s "https://app.formapi.io/api/v1/combined_submissions/$1" \
    -u "$API_TOKEN_ID:$API_TOKEN_SECRET"
}

get_json_value() {
  echo "$1" | sed -n 's/.*"'"$2"'":"\([^"]\+\)".*/\1/p'
}

RESPONSE=$(combine_submissions)
echo $RESPONSE
SUBMISSION_ID=$(get_json_value "$RESPONSE" id)
SUBMISSION_STATE=$(get_json_value "$RESPONSE" state)

echo "Waiting for PDF to be processed..."
while [[ "$SUBMISSION_STATE" = "pending" ]]; do
  sleep 1
  RESPONSE=$(get_combined_submission "$SUBMISSION_ID")
  SUBMISSION_STATE=$(get_json_value "$RESPONSE" state)
done

echo "Download your combined PDF at:"
get_json_value "$RESPONSE" download_url

results matching ""

    No results matching ""