NAV
shell python csharp

Back to Home

Introduction

Welcome to the apitemplate.io API! You can use our API to generate PDFs and images(JPEG and PNG) from templates with JSON data.

C#, Python3 or UIPath Libary & Code sample

The steps to produce PDFs/Images as follows:

  1. Design your template(s) and save it
  2. Integrate your workflow(either Zapier or any programming languages that support REST API) to send us the JSON data
  3. Our REST API returns download url for the images(PNG and JPEG) or PDFs

We have snippets in cURL, Python, and C#, you can view code examples in the dark area to the right and switch the programming language of the examples with the tabs in the top right.

Authentication

Template id and api key are mandatory in the HTTP/HTTPS request and they can be obtained in your web console.

The followings are the fields of a HTTP/HTTP request:

Option Description
Method POST
URL https://api.apitemplate.io/v1/create?template_id=[template_id]
Header X-API-KEY: [API_KEY]
Body [JSONDATA]

apitemplate.io expects for the API key to be included in all API requests to the server in a header that looks like the following:

X-API-KEY: [API_KEY]

API endpoints

Create a PDF

This endpoint creates a PDF file with JSON data and your template

curl --header "Content-Type: application/json" \
-iL \
-H 'X-API-KEY: 6fa6g2pdXGIyxHRhVlGh7U5Vhdckt' \
  --data '{"message": "The greatest glory in living lies not in never falling", "author": "Nelson Mandela", "width": 300}' \
  "https://api.apitemplate.io/v1/create?template_id=79667b2b1876e347"

# Github library https://github.com/APITemplate-io/Python-Integration

import requests, json

def main():
    api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt"
    template_id = "79667b2b1876e347"

    data = {
        "message": "The greatest glory in living lies not in never falling",
        "author": "Nelson Mandela",
    }

    response = requests.post(
        F"https://api.apitemplate.io/v1/create?template_id={template_id}",
        headers = {"X-API-KEY": F"{api_key}"},
        json= data
    )

if __name__ == "__main__":
    main()

// https://github.com/APITemplate-io/CSharp-Integration

using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

namespace csharp
{
    class ReturnContent{
        public string download_url{get;set;}
        public string status{get;set;}
    }

    class Program
    {
        static async Task Main(string[] args)
        {
            var api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
            var template_id = "79667b2b1876e347";
            var url = $"https://api.apitemplate.iocreate?template_id={template_id}";

            var data = new{
                message = "The greatest glory in living lies not in never falling",
                author = "Nelson Mandela"
            };


            var json_content = JsonSerializer.Serialize(data);
            var buffer = System.Text.Encoding.UTF8.GetBytes(json_content);
            var byteContent = new ByteArrayContent(buffer);

            Console.WriteLine(json_content);

            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("X-API-KEY",api_key);
            var response = await client.PostAsync(url,byteContent);
            var ret = await response.Content.ReadAsStringAsync();

            var returnContent = JsonSerializer.Deserialize<ReturnContent>(ret);

            if(returnContent.status=="success"){
                Console.WriteLine($"Downloading {returnContent.download_url}...");
                var download_response = await client.GetAsync(returnContent.download_url);
                using (var stream = await download_response.Content.ReadAsStreamAsync())
                {
                    var fileInfo = new FileInfo("image.jpeg");
                    using (var fileStream = fileInfo.OpenWrite())
                    {
                        await stream.CopyToAsync(fileStream);
                    }
                }
            }
        }
    }
}

The above command returns JSON structured like this:

{
   "download_url":"https://bucket.s3.amazonaws.com/91f62769-69e4-48bf.jpeg",
   "template_id":"cd890b2b199c5c42",
   "transaction_ref":"28f37353-69e4-48bf-b890-7a01c3a57e48",
   "status":"success"
}

HTTP Request

Option Description
Method POST
URL https://api.apitemplate.io/v1/create?template_id=[template_id]
Header X-API-KEY: [API_KEY]
Body [JSONDATA]

POST Body

[JSONDATA] HTTP Body is the JSON data

Query Parameters

[template_id] is mandatory and it can be obtained in the web console

Create an image (JPEG and PNG)

This endpoint creates a JPEG file(along with PNG) with JSON data and your template

The following is the json format in the post body to generate an image

{
    "overrides": [
        {
            "name": <object name 1>,
            "property_1": "<value 1>",
            ...
        },
        {
            "name": <object name 2>,
            "property_2": "<value 2>",
            ...
        }
    ]
}

The snippet to generate an image

curl --header "Content-Type: application/json" \
-iL \
-H 'X-API-KEY: 6fa6g2pdXGIyxHRhVlGh7U5Vhdckt' \
  --data '{ "overrides": [ {"name": "text_1", "text": "hello world", "textBackgroundColor": "rgba(246, 243, 243, 0)" }] }' \
  "https://api.apitemplate.io/v1/create?template_id=79667b2b1876e347"

# Github library https://github.com/APITemplate-io/Python-Integration

import requests, json

def main():
    api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt"
    template_id = "79667b2b1876e347"

    data = {
        "overrides": [
            {
                "name": "text_1",
                "text": "hello world",
                "textBackgroundColor": "rgba(246, 243, 243, 0)"
            }
        ]
    }

    response = requests.post(
        F"https://api.apitemplate.io/v1/create?template_id={template_id}",
        headers = {"X-API-KEY": F"{api_key}"},
        json= data
    )

if __name__ == "__main__":
    main()

// https://github.com/APITemplate-io/CSharp-Integration

Coming soon

The above command returns JSON structured like this:

{
   "download_url":"https://bucket.s3.amazonaws.com/5641212-6e75.jpeg",
   "download_url_png":"https://bucket.s3.amazonaws.com/56423251-6e75.png",
   "template_id":"cd23222b188c5c42",
   "transaction_ref":"56413f91-6e75-47a1-93af-344b2f23552e2",
   "status":"success"
}

HTTP Request

Option Description
Method POST
URL https://api.apitemplate.io/v1/create?template_id=[template_id]
Header X-API-KEY: [API_KEY]
Body [JSONDATA]

POST Body

[JSONDATA] HTTP Body is the JSON data

Query Parameters

[template_id] is mandatory and it can be obtained in the web console

List templates

Retrieves the information of templates

curl --header "Content-Type: application/json" \
-H 'X-API-KEY: 6fa6g2pdXGIyxHRhVlGh7U5Vhdckt' \
"https://api.apitemplate.io/v1/list-templates"
# Github library https://github.com/APITemplate-io/Python-Integration

import requests, json

def main():
    api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt"
    template_id = "79667b2b1876e347"

    response = requests.get(
        F"https://api.apitemplate.io/v1/list-templates",
        headers = {"X-API-KEY": F"{api_key}"},
        json= data

    )
if __name__ == "__main__":
    main()

// https://github.com/APITemplate-io/CSharp-Integration

Coming soon

The above command returns JSON structured like this:

{
   "status":"success",
   "templates":[
      {
         "template_id":"9d188b2b18815a89",
         "name":"PDF Contract 1",
         "format":"PDF"
      },
      {
         "template_id":"33188b2b188edc45",
         "name":"Instragram quote",
         "format":"JPEG"
      },
      {
         "template_id":"0b388b2b1886a890",
         "name":"PDF Contract 1",
         "format":"PDF"
      }
   ]
}

HTTP Request

Option Description
Method GET
URL https://api.apitemplate.io/v1/list-templates
Header X-API-KEY: [API_KEY]

Query Parameters

[template_id] is mandatory and it can be obtained in the web console

Errors

A success message

{
    "status" : "success
}

An error message

{
    "status" : "error",
    "message": "Invalid api key"
}

Aside the returning message, apitemplate.io API uses the following error codes:

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Your API key is wrong.
404 Not Found -- The specified template could not be found.
405 Method Not Allowed -- You tried to access an endpoint with an invalid method.
406 Not Acceptable -- You requested a format that isn't json.
429 Too Many Requests -- Too many request! Slow down!
500 Internal Server Error -- We had a problem with our server. Try again later.
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.