Document generation options in Zapier

Generating your first Document with Zapier

This article is dedicated to advanced features or our Zapier integration. If you wish to learn how to generate your first Document using Zapier, we have a dedicated guide you can read:

pageGenerating your first Document with Zapier

Advanced JSON

Be careful!

With great power comes… great trouble sometimes. Only switch to advanced JSON if you know what you’re doing and know how to escape your data properly.

See Fixing frequent Zapier errors for more information.

By default, our integration provides a very simple mapping field to define what will be sent to PDFMonkey.

In most cases the simple mapping will be good enough. But there might be cases where you want to structure your data in a different way. That's where the Use a custom JSON structure option can be useful.

It will switch from the simple mapping to a text area where you can insert your own JSON and use nested properties:

Custom Filename

You can specify a custom name for the generated PDF. This might be useful if you plan on storing this file in a private space like Drive or Dropbox.

You can use dynamic parts to build this filename but be careful of a few things:

  • The filename should not contain any slash / or backslash \

  • Non-latin characters should be avoided as they can be messed-up when saving the file

We usually recommend to use short name based on dates or IDs.

Attaching meta-data to your Documents

When you generate a Document, you can attach meta-data to it. Meta-data are not available in the Template and cannot be used ton influence the content of the Document. They’re simply attached to it.

A common use-case is receiving the Document via a webhook and using one of its meta-data to handle it differently.

Using line items

If you're editing an invoice or a quote, you will likely need to deal with line items. Zapier offers a great way to access those items if the trigger you use supports them.

Let's take the example of a Stripe invoice. Items in the invoice will be available through a Line Items collection.

To send those items in a way that can be understood by PDFMonkey, you need to set Add Line Items to Yes.

It will open a new section where you can specify what a single item should look like.

For the sake of this article, we created a Stripe invoice with the following items:

Delicious waffle         3.50€      x12      = 42.00€
Perfectly round donut    4.99€      x5       = 24.95€
TOTAL                                          66.95€

While the TOTAL itself should be sent as basic data for the Document, the name, unit price, quantity and total amount for each item should be sent as line items from Zapier:

Mapping or JSON

Note that the field to define the data for a line item will use the same form as the main data. If you use advanced JSON for the main data, the line item payload will also be defined using advanced JSON.

Using the line items in your Template

When Zapier sends the line items to PDFMonkey, they will be accessible through a special lineItems variable. In our case, the payload would look like this:

JSON
{
  "lineItems": [
    {
      "product": "Delicious waffle",
      "quantity": "12",
      "unitPrice": "3.50",
      "totalAmount": "42.00"
    },
    {
      "product": "Perfectly round donut",
      "quantity": "5",
      "unitPrice": "4.99",
      "totalAmount": "24.95"
    }
  ]
}

Only strings attached

If you pay close attention to the payload above, only string are sent in the payload. Zapier doesn’t make any difference between text and numbers.

Luckily enough, Liquid (the template we use) is smart enough to convert those values to numbers when you do math with them. But just keep this fact in mind if you run into trouble with numbers.

You can loop over the lineItems array to display content for each item individually:

HTML
{% for item in lineItems %}
  <p>{{item.product}} at {{item.unitPrice}}€ x{{item.quantity}} = {{item.totalAmount}}€</p>
{% endfor %}

This would result in the following HTML:

HTML
<p>Delicious waffle at 3.50€ x12 = 42.00€</p>
<p>Perfectly round donut at 4.99€ x5 = 24.95€</p>

Usually you will probably want to build a table row for each item but this should give you a good idea of how to achieve that.

Last updated