How to Handle Complex Data/Line items For CraftMyPDF Integrations

Table of Contents

CraftMyPDF offers an advanced drag-and-drop editor and we empower businesses and individuals to automate document generation with no-code platforms like Make.com(Formerly Integromat) and Zapier.

Our integrations for Make.com and Zapier support 2 types of Payload Types. The payload types are:

  • Dictionary: For simple data, it’s a collection of key-value pairs which each key is associated with a value.
  • JSON Data: For complex data, it includes the basic data types — strings, numbers, arrays, booleans, and other objects. JSON data can contain objects and arrays.

In this tutorial, we are going to explore the ways to handle complex data(line items, or arrays) by using JSON for Make.com and Zapier.

How to Handle Line Items for Make.com

Transforming data from Google Spreadsheet or Airtable is easy with Array Aggregator and JSON module, the following section is a step-by-step guide to creating JSON strings from Google sheets.

1. Prepare Google Spreadsheet data

In this section, we are going to use a Google Spreadsheet for the data source. You may use other data sources like Airtable. The following is the Google Spreadsheet:

2. Add & Configure Google Sheets App

Firstly create a new Scenario in Make.com. You may use any triggers or leave it.

Then, create a new action by searching for Google Sheets module and use the Search Rows action.

Next is to configure the action by connecting the action to your google account, choose your SpreadSheet and select the Sheet.

3. Configure JSON module

Next, create a subsequent action and search, add the JSON app

Select Create JSON module

Next is to configure the Create JSON module. Firstly click on the Add button. It brings up a dialog and name your data structure as Line items and click on Generate

Paste the JSON (You can copy the JSON from the CraftMyPDF Data tab in the template editor) and click on the Generate button. Close all the dialogues and save all the settings.

4. Add an Array Aggregator

Now we need to add an Array Aggregator between Google Sheets and JSON module as the arrow shown below:

To do so, click on the Tools icon and select Array aggregator

Arrange the Array aggregator to be in between Google Sheets and JSON

Then, configure the Array aggregator. Select items for the Target structure type

Map all fields of the Google spreadshets to the items as follows.

5. Map the List Items Array to the JSON

Now, go back to the Create JSON module and map the field by toggling the Map button. Then select Array[] of Array aggregator. Press the OK button to save the settings.

You may now run the scenario to look at the JSON string

6. Configure CraftMyPDF app

Search for CraftMyPDF app and select the Generate PDF module

i. Configure the connection, the API Key can be obtained from the CraftMyPDF API Integration tab.

ii. Select JSON(Complex Dynamic Data) as the Payload Type

iii. Select JSON string from the Create JSON module

iv. Select a Template ID

Now, run the scenario to generate a PDF.

How to Handle Line Items for Zapier

The following section is to make use of Code by Zapier to create a JSON string for CraftMyPDF integration.

1. Setup Trigger

Setup the trigger, you may use any triggers that you find appropriate.

2. Add and Setup Google Sheets

Next is to create a new action. Search for Google Sheets for the app and select Get Many Spreadsheet Rows(Advanced, With Line Item Support)

3. Create a Setup Code by Zapier

Create a new action, look for Code by Zapier, and select Run Javascript for the event.

In the Input Data, enter all the keys, it includes the rows, invoice number, and currency. For the rows key, select Raw Rows of the Google Sheets

Enter the code snippet into the Code

let objs = JSON.parse(inputData.rows);
let items = [];

    "description": obj[0],
    "quantity": parseFloat(obj[1]),
    "unit_price": parseFloat(obj[2]),
    "total": parseFloat(obj[3]),

let result = {
    "invoice_number": inputData.invoice_number,
    "currency": inputData.currency,

output = {"json" : JSON.stringify(result), "count": objs.length};

4. Create a CraftMyPDF Action

Create a new action, Select CraftMyPDF.com for the app and Create PDF for the event.

In the Set up action

(i) Select a template

(ii) For the Payload Type select JSON

(iii) For JSON Payload, select the JSON string generated by the Zapier by Code

Recent Posts
Copyright ©2022 CraftMyPDF.com

Email us at hello@craftmypdf.com for support