Issue with Generating Invoice PDF Using PDF Monkey

Hello, dear Glide Makers!

I’m facing an issue while trying to insert my JSON data into PDF Monkey to generate an invoice document.

Context:

I have built a template that generates an invoice based on the products a user selects in their cart. Each product is stored in one or multiple warehouses, each with different delivery times. The invoice needs to reflect this by displaying the products in separate tables based on their respective storage locations and delivery times.

To achieve this, I created an IF condition in my template to check each product’s storage and dynamically display it in the relevant table along with its quantity, price, and expected delivery time.

My HTML code piece with a table

<!-- Table of products for Storage 1 -->
{% assign storage1_items = false %}
{% for item in items %}
    {% if item.storage1 != "" %}
        {% assign storage1_items = true %}
    {% endif %}
{% endfor %}

{% if storage1_items %}
    <h2>Products (Delivery time: {{ items[0].storage1_time }})</h2>
    <table class="product-table">
        <tr>
            <th>No.</th>
            <th>Products (works, services)</th>
            <th>Quantity</th>
            <th>Unit</th>
            <th>Price</th>
            <th>Total</th>
        </tr>
        {% for item in items %}
            {% if item.storage1 != "" %}
            <tr>
                <td>{{ forloop.index }}</td>
                <td>{{ item.description }}</td>
                <td>{{ item.storage1 }}</td>
                <td>pcs</td>
                <td>{{ item.price }}</td>
                <td>{{ item.price | times: item.storage1 }}</td>
            </tr>
            {% endif %}
        {% endfor %}
    </table>
{% endif %}

<!-- Table of products for Storage 2 -->
{% assign storage2_items = false %}
{% for item in items %}
    {% if item.storage2 != "" %}
        {% assign storage2_items = true %}
    {% endif %}
{% endfor %}

{% if storage2_items %}
    <h2>Products (Delivery time: {{ items[0].storage2_time }})</h2>
    <table class="product-table">
        <tr>
            <th>No.</th>
            <th>Products (works, services)</th>
            <th>Quantity</th>
            <th>Unit</th>
            <th>Price</th>
            <th>Total</th>
        </tr>
        {% for item in items %}
            {% if item.storage2 != "" %}
            <tr>
                <td>{{ forloop.index }}</td>
                <td>{{ item.description }}</td>
                <td>{{ item.storage2 }}</td>
                <td>pcs</td>
                <td>{{ item.price }}</td>
                <td>{{ item.price | times: item.storage2 }}</td>
            </tr>
            {% endif %}
        {% endfor %}
    </table>
{% endif %}

<!-- Table of products for Storage 3 -->
{% assign storage3_items = false %}
{% for item in items %}
    {% if item.storage3 != "" %}
        {% assign storage3_items = true %}
    {% endif %}
{% endfor %}

{% if storage3_items %}
    <h2>Products (Delivery time: {{ items[0].storage3_time }})</h2>
    <table class="product-table">
        <tr>
            <th>No.</th>
            <th>Products (works, services)</th>
            <th>Quantity</th>
            <th>Unit</th>
            <th>Price</th>
            <th>Total</th>
        </tr>
        {% for item in items %}
            {% if item.storage3 != "" %}
            <tr>
                <td>{{ forloop.index }}</td>
                <td>{{ item.description }}</td>
                <td>{{ item.storage3 }}</td>
                <td>pcs</td>
                <td>{{ item.price }}</td>
                <td>{{ item.price | times: item.storage3 }}</td>
            </tr>
            {% endif %}
        {% endfor %}
    </table>
{% endif %}

My Data structure

{
  "invoice_number": "1",
  "date": "01/02/2025",
  "eur_rate": "102.1301",
  "buyer": {
    "user_id": "qE66fsG0SvufjorYzTEO9w",
    "company_name": "",
    "inn": "",
    "kpp": "",
    "address": ""
  },
  "items": [
    {
      "product_id": "2CDG110211R0011",
      "description": "Fan coil controller, 2 x PWM, manual control, 3 stages, MDRC",
      "total_quantity": "300",
      "price": "24483.6",
      "storage1": "10",
      "storage2": "4",
      "storage3": "286",
      "storage1_time": "3-4 days",
      "storage2_time": "2-3 weeks",
      "storage3_time": "8-10 weeks"
    },
    {
      "product_id": "2CKA006132A0342",
      "description": "KNX Presence Mini White",
      "total_quantity": "20",
      "price": "13267.7",
      "storage1": "20",
      "storage2": "",
      "storage3": "",
      "storage1_time": "3-4 days",
      "storage2_time": "",
      "storage3_time": ""
    }
  ]
}

Problem:

When I try to send this JSON data to PDF Monkey via an Action in Glide, it refuses to generate the document.

  • I’m taking the final JSON output and sending it to PDF Monkey, but it fails every time.
  • No matter how I modify my data structure, the request does not go through, and I receive an error message.

Has anyone faced a similar issue when sending JSON data to PDF Monkey?
What could be causing this error? Any suggestions on how to properly structure the JSON request or debug the issue?

Thanks in advance! :rocket:

My PDF Monkey isn’t working either…
Was working fine and stopped suddenly.

1 Like

Ok figured it was a bug with the license. Nothing to do with Glide.

If you use the PDFMonkey interface to test out that JSON, is it working?

Yes, it works fine, no errors.

I tried first to send the whole JSON as one value inside integration, than made each value as a separate object. Nothing changed

Here is data JSON that is sent to PDFMonkey

I would check two things:

  • Does your filename contain the .pdf extension? If not, try to add it and see if it works.
  • I see your structure contains an array. I would check the PDFMonkey logs (they do add this to your PDFMonkey dashboard), see the document that was generated, and see if Glide sends valid JSON over. There’s a chance that array is seen as text.
1 Like

I tried adding “.pdf” to the filename, but it didn’t change anything. I suspect the issue is with the items array.

  • I checked the PDFMonkey logs, but no document was generated, so I can’t see what data is actually being received.
  • The items array is coming from a Query JSON column in Glide, which extracts only the items object from the whole JSON structure.
  • Here’s the exact format of what I’m sending inside "items":
[
  {
    "product_id": "2CDG110274R0011",
    "description": "DALI Gateway, Premium, 2-channel, MDRC",
    "total_quantity": "14",
    "price": "44615.17",
    "total_price": "624,612.38",
    "storage1": "14",
    "storage2": "",
    "storage3": "",
    "storage1_time": "3-4 days",
    "storage2_time": "",
    "storage3_time": ""
  },
  {
    "product_id": "2CDG110110R0011",
    "description": "Safety Terminal, 8-channel, MDRC",
    "total_quantity": "2",
    "price": "26406.59",
    "total_price": "52,813.18",
    "storage1": "2",
    "storage2": "",
    "storage3": "",
    "storage1_time": "3-4 days",
    "storage2_time": "",
    "storage3_time": ""
  },
  {
    "product_id": "2CDG110275R0011",
    "description": "Uninterruptible Power Supply KNX, 640mA, MDRC",
    "total_quantity": "1",
    "price": "28780.42",
    "total_price": "28,780.42",
    "storage1": "1",
    "storage2": "",
    "storage3": "",
    "storage1_time": "3-4 days",
    "storage2_time": "",
    "storage3_time": ""
  }
]

and this is what I got inside Glide logs:

"items":"{"product_id":"2CDG110274R0011","description":"DALI Шлюз, Премиум, 2-кратный, MDRC","total_quantity":"14","price":"44615.17","total_price":"624,612.38","storage1":"14","storage2":"","storage3":"","storage1_time":"3-4 дня","storage2_time":"","storage3_time":""},{"product_id":"2CDG110110R0011","description":"Терминал безопасности, 8-кратный, MDRC","total_quantity":"2","price":"26406.59","total_price":"52,813.18","storage1":"2","storage2":"","storage3":"","storage1_time":"3-4 дня","storage2_time..."
"eur_rate":""
"total_amount":""
"invoice_number":2
"total_amount_text":""
}

Question:

How should I modify the array format to ensure PDFMonkey processes it correctly?
Could the Query JSON column in Glide be changing the format in a way that makes it invalid for PDFMonkey?

1 Like

It might be just the integration not built for nested arrays. I would try sending the full payload to Make, generate with PDFMonkey over there, and bring the file back to Glide.

I am doing that so I don’t think this is the issue.

Can you share how you’re structuring your JSON in Glide, and sample data in PDFMonkey?

Sure

Also, @Bio_Sam , can you check the logs of your action to see if you can see the fullJSON Glide sends to PDFMonkey?

I think what you copied in your last comment got cutoff, so I’m not sure if the full thing is valid JSON.

Here we go.

My is starting by a raw text json:

Then I format it to JSON:


I create a body for my webhook call:


In the webhook, I query my data including the JSON arrays:

Generate PDFMonkey action:

And it works like a charm!

You’re using JSON Template there. If you use Query JSON, does it work?

Asking because I have seen this problem before, JSON Template/Query JSON making the output invalid JSON. I actually discussed it with Rupert (the DocsAutomator guy) in one of our chats.

I am using both. And also JSON Object for some.

Do you know if glide is planning to add this feature ?
All my pdf uses nested array im forced to use make instead like you said.

1 Like

Maxime’s test shows that it might be baked in already, so I suggest testing to see if it works for you.

Exactly! @Xavier9 Try it, it works like a charm!

I tested this today in a production app. I’m surprised that both JSON Template and JSON Object can not produce a valid JSON for PDFMonkey and it has to be through trigger webhook > query JSON like you did.

It should work, but to me JSON Template and JSON Object should work directly in the PDFMonkey integration, not this workaround.

Edit: Probably talked too soon :sweat_smile:

1 Like

Yes this method works great, im doing something similar with webhooks and make but i was talking about the native integration in glide of pdf Monkey.

the native one displays the pdf much faster but you can’t add an array of items.

2 Likes

I’m requesting this in experts’ Slack channel.

4 Likes