Fixing frequent Zapier errors

Download URL expired

If you get an expired Download URL error during the building of your Zap, try reloading the example record in your trigger.

Since the Download URL is only valid for 1h, you need to refresh the Documents in Zapier to get new Download URL. You can do so by clicking the Load More button in the Test section of your trigger.

Generation output

This tip is for the trigger but it will not apply for the output of a Generate Document action. Is this case you will need to generate a new Document in order to get fresh data and a valid Download URL.

422 Responses

This error will usually happen if you use the custom JSON option to write your Zap but have values that need escaping before being sent to PDFMonkey.

Values containing double quotes

Let's say you defined the following custom JSON:

Custom JSON
{
  "user": {
    "name": "(Dynamic Field From Zapier)"
  }
}

If the value in Dynamic Field From Zapier contains quotes, the constructed JSON will end-up broken. Let's take Peter "Spiderman" Parker as an example. Here is what the end JSON would look like:

Invalid JSON
{
  "user": {
    "name": "Peter "Spiderman" Parker"
  }
}

As we can see, it will not be a valid JSON payload when it's sent over the wire.

HTML attributes

If you send HTML for instance this will happen a lot as 99% of the time attributes use double quotes to set their value (ex: <div class="test">)

What you actually want is to escape those double quotes so that your JSON remains valid:

Valid JSON
{
  "user": {
    "name": "Peter \"Spiderman\" Parker"
  }
}

Values containing line breaks

JSON doesn't support values that include line breaks, so this is invalid JSON:

Invalid JSON
{
  "userBio": "Once upon a time,
They lived happily ever after."
}

What you want to do instead is escape those line breaks by either replacing them with a <br> tag or transform them to the text representation of a line break (\n).

Valid JSON
{
  "userBio": "Once upon a time,\nThey lived happily ever after."
}

Solution

Do you really need custom JSON?

The first question to ask yourself is "Do you really need custom JSON?". In most cases, the simple mapping approach will be good enough and will make your life easier as it will take care of escaping everything automatically.

If you can't escape the values before they reach Zapier, the next best solution is to add a Code by Zapier action before calling PDFMonkey.

Let's say you data contain both line breaks and double quotes and are looking like this:

ItemValue

Trigger App User Bio

This is the bio of the user.

It's a free form text that the user can edit so it can contain line breaks.

It could even be split in a few paragraphs… why not?

Trigger App User Name

Peter Parker

Trigger App User Full Name

Peter "Spiderman" Parker

Here we need to escape values for both Trigger App User Bio and Trigger App User Full Name. Let's start by adding a Code by Zapier action to our Zap and selecting Run Javascript :

We can now give our fields names that will help us identify them in the following steps:

And now we'll add the magic that will solve our issue, the actual code:

Code by Zapier
let data = Object.assign({}, inputData);

for (let key in data) {
  if (typeof(data[key]) === "string" && data[key].length > 0) {
    data[key] = data[key].replace(/\r?\n/g, '<br>').replace(/\t/g, " ").replace(/"/g, '\\\"');
  }
}

output = [data];

It will give you the same fields in the output but with their value properly escaped:

You can now use those values when building your PDFMonkey payload.

Notice how here we used the fields coming from the second step and not from the trigger.

Last updated