Create PDFs

These calls return a PDF of a Smartform directly in the response, so your system gets the document without waiting for a person to fill in the form.

Every call needs a bearer token from a Standard API client. See Authentication.

The four calls

CallWhat it does
POST /Integrations/dialog/json/pdfCreates a form from your values and returns it as a PDF. Nobody is notified, even if the body lists participating parties.
POST /Integrations/dialog/json/submit/pdfCreates the form, submits it and returns the PDF. Participating parties in the body are notified by email or SMS.
GET /Integrations/dialogDefinitions/{dialogDefinitionId}/dialogValues/{dialogValuesId}/pdfReturns the PDF of a form that already exists, with its PDF attachments from the toolbar appended.
POST /Integrations/pdf/createReturns the PDF of an existing form. The ids go in the body as smartformId and smartformValueId. Attachments are not appended.

The first two take the same body as Create a Smartform. All four return the file as application/pdf.

📝 Note: A multi-step Smartform stays in progress after submit/pdf. The call completes the step, not the whole form, so no completion notification is sent. The PDF comes back either way, so check the form itself before you treat it as closed.

Options

  • languageCode is a query parameter on the first three calls. It renders the document in that language. Leave it out to use the default language of the Smartform.
  • The PDF of an existing form only appends PDF files held as toolbar attachments. Files uploaded into the fields of the form are not part of the document. Read them with Read and delete forms.
  • A smartformValueId that belongs to another Smartform is rejected. A form that does not exist is answered with 404, and 400 when smartformId or smartformValueId is missing.

Environment

The calls above also exist with the environment in the path, for example /Test/Integrations/dialog/json/pdf. The values are Development, Test, PreProduction and Production.

  • For the two calls that create a form, the environment selects the deployed version of the Smartform, as described in Create a Smartform.
  • For the two calls that return an existing form, the environment is checked and not applied. The PDF is made from the environment the form was filed under, and a different environment in the path is answered with 404. Forms created before environments were recorded are returned for any environment.

Example

This example creates a form from values and saves the PDF. Get the token as shown in Authentication.

const axios = require('axios').default;
const fs = require('fs');

async function createPdf(accessToken) {
  const response = await axios({
      method: 'POST',
      url: 'https://api.smartforms.metaforce.net/Test/Integrations/dialog/json/pdf?languageCode=en',
      headers: {
          'content-type': 'application/json',
          'Authorization': `Bearer ${accessToken}`
      },
      data: {
          dialogDefinitionId: '646f4127f70bcxxxxxxxxxxx',
          values: {
              name: 'Jon',
              city: 'Stockholm'
          }
      },
      responseType: 'arraybuffer'
  });

  fs.writeFileSync('form.pdf', response.data);
}