Articles on: Q&A

How to add my data?

Data format



The PDF Generator API expects that the data in the JSON format is sent via the API request. JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy to read and write, and easy for to parse and generate. It is widely used for transmitting data between a server and a web application as well as for storing configuration data.

Example:
{
  "employee": {
    "name": "John Smith",
    "age": 23,
    "position": "Developer",
    "skills": ["JavaScript", "Python", "SQL"],
    "isFullTime": true
  }
}


Objects: Enclosed in curly braces {}, with key-value pairs. {"key" : "value"} Keys are strings, and values can be strings, numbers, objects, arrays, true, false, or null.

Arrays: Enclosed in square brackets [], containing a list of values. You can iterate over an array using Table Component or Container Component.

Data Fields



Data Field is a placeholder within a template that is used to dynamically insert data from a JSON dataset. Each data field corresponds to a specific piece of data in your JSON structure.

For example, if your JSON dataset includes a customer's name {"customer_name" : "John"} , you can reference it in your template using a data field like {customer_name}. After generating the document our API merges template and JSON data together and data field {customer_name} will be replaced with John

How to add my data into a template



We do not store any of your data. Therefore you need to add your data every time you edit/create a template. You can add your data inside the editor or before opening a template.

1. Adding data in the editor


You open a template > select on the top menu INSERT > select DATA > and then you can either browse a local JSON file, use an URL to the file or paste your JSON data from clipboard.




2. Adding data before opening a template


When you open a new template or want to open an old template a menu pops out. You can upload JSON, upload CSV (which will be converted to JSON by the system), upload EXCEL (also will be converted), paste from clipboard or use sample data. Use Sample Data will create a JSON structure (only keys without any values) based on your existing template and you can fill this structure with dummy values.

You can also SKIP this part and go directly to the editor and add the data later according to the step 1.




How to add data via API



When doing an API request POST Generate Document, PDF Generator API expects that the data in the JSON format is sent in a body of the request in an object called "data". Below is an example of the object "data" that contains one integer value {id} and three string values {name}, {birthdate} and {role}. After inserting the template id with your template id the data will be merged with the template and data fields in the template {id} `{name}` {birthdate} and {role} will be replaced with actual values given in the API request 123 John Smith 2000-01-01 Developer

{
  "template": {
    "id": "REPLACE_TEMPLATE_ID",
    "data": {
      "id": 123,
      "name": "John Smith",
      "birthdate": "2000-01-01",
      "role": "Developer"
    }
  },
  "format": "pdf",
  "output": "base64",
  "name": "Invoice 123"
}

Updated on: 04/07/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!