Introduction
Welcome to the APITemplate.io API reference! You can use our API to generate PDFs and images (JPEG and PNG) from templates using JSON data.
Note: This is the version 1 of our REST API and it is no longer supported. It's recommended to use our latest version 2 REST API.
C#, Python3 or UIPath Libary & Code sample
- GitHub - APITemplate.io C# Library
- GitHub - APITemplate.io Python 3 Library
- GitHub - APITemplate.io UIPath Library
Steps to produce PDFs/Images as follows:
- Design your template(s) and save it
- Integrate your workflow(either with Zapier,Integromat or any programming languages that support REST API) to send us the JSON data
- 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 samples’ programming language with the top right tabs.
Authentication
The Template ID and API key are mandatory in the HTTP/HTTPS request, and they can be obtained in your web console.
The following 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 the API key to be part of all API requests to the server in a header in this format:
X-API-KEY: [API_KEY]
Optionally we also support Authorization header
Authorization: Token [API_KEY]
API endpoints
Note: Follow Redirects
Example for Node.js - enable followRedirect and followAllRedirects
{
headers: {
Accept: 'application/json',
"X-API-KEY": `${credentials.apiKey}`,
},
method,
body,
followRedirect: true,
followAllRedirects: true,
qs: query,
uri: uri || `https://api.apitemplate.io/v1${opt.resource}`,
json: true,
};
If you are using API for the integration, please make sure to enable follow redirect for your HTTP/HTTPS requests
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);
}
}
}
}
}
}
<?php
function generate($template_id,$api_key, $data) {
$url = "https://api.apitemplate.io/v1/create?template_id=" . $template_id;
$headers = array("X-API-KEY: ".$api_key);
$curl = curl_init();
if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
if (!$result) {
return null;
}else{
$json_result = json_decode($result, 1);
if($json_result["status"]=="success"){
return $json_result["download_url"];
}else{
return null;
}
}
}
$tempate_id = "79667b2b1876e347";
$api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
$json_payload='{"message": "The greatest glory in living lies not in never falling","author": "Nelson Mandela"}';
echo generate($tempate_id,$api_key,$json_payload);
?>
const { http, https } = require('follow-redirects');
var url = require("url");
function makeRequest(urlEndpoint, method, apiKey, data=null) {
let d = "";
if(data!=null) d = JSON.stringify(data);
const uri = url.parse(urlEndpoint);
const proto = uri.protocol === 'https:' ? https : http;
const opts = {
method: method,
headers: {
'Content-Length': d.length,
'Content-Type': 'application/json',
'X-API-KEY': apiKey
}
};
console.log(proto);
console.log(opts);
return new Promise((resolve, reject) => {
const req = proto.request(urlEndpoint, opts, (res) => {
res.setEncoding('utf8');
let responseBody = '';
res.on('data', (chunk) => {
responseBody += chunk;
});
res.on('end', () => {
resolve(responseBody);
});
});
req.on('error', (err) => {
reject(err);
});
if(data) {
req.write(d);
}
req.end();
});
}
let apiKey = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
let template_id = '79667b2b1876e347';
(async () => {
let resp = await makeRequest("https://api.apitemplate.io/v1/create?template_id=" +template_id,"POST",apiKey,{
"message": "The greatest glory in living lies not in never falling",
"author": "Nelson Mandela"
});
let ret = JSON.parse(resp);
console.log(resp);
})();
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]&export_type=[export_type]&output_html=[either 0 or 1]&filename=[filename] |
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[output_html]
is optional, either0
or1
, default to0
. To enable output of html content, set the value to1
and it will return in the JSON response ashtml_url
field (as a URL)[export_type]
is optional, eitherjson
orfile
, default tojson
.- The option
json
returns a JSON object, and the output PDF stores on a CDN - The option
file
returns binary data of the generated PDF(More secure and completely private) and the response HTTP headerContent-Disposition
is set toattachment
.
- The option
[filename]
is optional, default to a UUID (e.g0c93bd9e-9ebb-4634-a70f-de9131848416.pdf
).
Create a PDF (Asynchronously thru webhook)
This endpoint creates a PDF document asynchronously with JSON data and your template.
The API returns immediately and once the PDF document is generated, it will make a HTTP/HTTPS GET to your URL(will retry for 3 times before giving up)
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&webhook=1&webhook_url=https%3A%2F%2Fyourwebserver.com"
The above command returns JSON structured like this:
{
"status":"success",
"is_webhook":1,
"webhook_url":"https://yourwebserver.com",
"transaction_ref":"b692183d-46d7-3213-891a-460a5814ad3f"
}
HTTP Request
Option | Description |
---|---|
Method | POST |
URL | https://api.apitemplate.io/v1/create?template_id=[template_id]&webhook=1&webhook_url=[call_back_url]&output_html=[either 0 or 1]&filename=[filename] |
Header | X-API-KEY: [API_KEY] |
Body | [JSONDATA] |
POST Body
[JSONDATA] HTTP Body is the JSON data
URL/Query Parameters
webhook
is always set to 1[template_id]
is mandatory and it can be obtained in the web console[call_back_url]
is the URL of your webhook URL, it starts with http:// or https:// and has to be urlencoded[output_html]
is optional and either0
or1
, default to0
. To enable output of html content, set the value to1
and it will return in the JSON response ashtml_url
field (as a URL)[filename]
is optional, default to a UUID (e.g0c93bd9e-9ebb-4634-a70f-de9131848416.pdf
).
Webhook URL for generated PDF
Once the PDF is generated our services will make a HTTP/HTTPS GET call to the following URL
https://[yourwebserver.com]?&primary_url=[primary_url]&transaction_ref=[transaction_ref]&html_url=[html_url]
[yourwebserver.com]
is your web services to handle the callback[primary_url]
is the URL to the PDF document[html_url] is the URL to a HTML page if
output_htmlis set to
1`[transaction_ref]
is the transaction reference number
The following is a sample Webhook URL
https://yourwebserver.com?&primary_url=https%3A%2F%2Fpub-cdn.apitemplate.io%2F2021%2F06%2Fb692183d-46d7-3213-891a-460a5814ad3f.pdf&transaction_ref=b692183d-46d7-3213-891a-460a5814ad3f
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
<?php
function generate($template_id,$api_key, $data) {
$url = "https://api.apitemplate.io/v1/create?template_id=" . $template_id;
$headers = array("X-API-KEY: ".$api_key);
$curl = curl_init();
if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
if (!$result) {
return null;
}else{
$json_result = json_decode($result, 1);
if($json_result["status"]=="success"){
return $json_result["download_url"];
}else{
return null;
}
}
}
$tempate_id = "79667b2b1876e347";
$api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
$json_payload='{ "overrides": [ {"name": "text_1", "text": "hello world", "textBackgroundColor": "rgba(246, 243, 243, 0)" }] }';
echo generate($tempate_id,$api_key,$json_payload);
?>
const { http, https } = require('follow-redirects');
var url = require("url");
function makeRequest(urlEndpoint, method, apiKey, data=null) {
let d = "";
if(data!=null) d = JSON.stringify(data);
const uri = url.parse(urlEndpoint);
const proto = uri.protocol === 'https:' ? https : http;
const opts = {
method: method,
headers: {
'Content-Length': d.length,
'Content-Type': 'application/json',
'X-API-KEY': apiKey
}
};
console.log(proto);
console.log(opts);
return new Promise((resolve, reject) => {
const req = proto.request(urlEndpoint, opts, (res) => {
res.setEncoding('utf8');
let responseBody = '';
res.on('data', (chunk) => {
responseBody += chunk;
});
res.on('end', () => {
resolve(responseBody);
});
});
req.on('error', (err) => {
reject(err);
});
if(data) {
req.write(d);
}
req.end();
});
}
let apiKey = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
let template_id = '79667b2b1876e347';
(async () => {
let resp = await makeRequest("https://api.apitemplate.io/v1/create?template_id=" +template_id,"POST",apiKey,
{ "overrides": [ {"name": "text_1", "text": "hello world", "textBackgroundColor": "rgba(246, 243, 243, 0)" }] });
let ret = JSON.parse(resp);
console.log(resp);
})();
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}"},
)
if __name__ == "__main__":
main()
// https://github.com/APITemplate-io/CSharp-Integration
Coming soon
<?php
function list_templates($api_key) {
$url = "https://api.apitemplate.io/v1/list-templates";
$headers = array("X-API-KEY: ".$api_key);
$curl = curl_init();
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
if (!$result) {
return null;
}else{
$json_result = json_decode($result, 1);
return $json_result;
}
}
$api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
print_r(list_templates($api_key));
?>
const { http, https } = require('follow-redirects');
var url = require("url");
function makeRequest(urlEndpoint, method, apiKey, data=null) {
let d = "";
if(data!=null) d = JSON.stringify(data);
const uri = url.parse(urlEndpoint);
const proto = uri.protocol === 'https:' ? https : http;
const opts = {
method: method,
headers: {
'Content-Length': d.length,
'Content-Type': 'application/json',
'X-API-KEY': apiKey
}
};
console.log(proto);
console.log(opts);
return new Promise((resolve, reject) => {
const req = proto.request(urlEndpoint, opts, (res) => {
res.setEncoding('utf8');
let responseBody = '';
res.on('data', (chunk) => {
responseBody += chunk;
});
res.on('end', () => {
resolve(responseBody);
});
});
req.on('error', (err) => {
reject(err);
});
if(data) {
req.write(d);
}
req.end();
});
}
let apiKey = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
(async () => {
let resp = await makeRequest("https://api.apitemplate.io/v1/list-templates","GET",apiKey);
let ret = JSON.parse(resp);
console.log(ret);
})();
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] |
List objects
Retrieves the information of all the generated images and PDFs
curl --header "Content-Type: application/json" \
-H 'X-API-KEY: 6fa6g2pdXGIyxHRhVlGh7U5Vhdckt' \
"https://api.apitemplate.io/v1/list-objects"
# Github library https://github.com/APITemplate-io/Python-Integration
import requests, json
def main():
api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt"
response = requests.get(
F"https://api.apitemplate.io/v1/list-objects",
headers = {"X-API-KEY": F"{api_key}"},
)
if __name__ == "__main__":
main()
// https://github.com/APITemplate-io/CSharp-Integration
Coming soon
<?php
function list_objects($api_key) {
$url = "https://api.apitemplate.io/v1/list-objects";
$headers = array("X-API-KEY: ".$api_key);
$curl = curl_init();
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
if (!$result) {
return null;
}else{
$json_result = json_decode($result, 1);
return $json_result;
}
}
$api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
print_r(list_objects($api_key));
?>
const { http, https } = require('follow-redirects');
var url = require("url");
function makeRequest(urlEndpoint, method, apiKey, data=null) {
let d = "";
if(data!=null) d = JSON.stringify(data);
const uri = url.parse(urlEndpoint);
const proto = uri.protocol === 'https:' ? https : http;
const opts = {
method: method,
headers: {
'Content-Length': d.length,
'Content-Type': 'application/json',
'X-API-KEY': apiKey
}
};
console.log(proto);
console.log(opts);
return new Promise((resolve, reject) => {
const req = proto.request(urlEndpoint, opts, (res) => {
res.setEncoding('utf8');
let responseBody = '';
res.on('data', (chunk) => {
responseBody += chunk;
});
res.on('end', () => {
resolve(responseBody);
});
});
req.on('error', (err) => {
reject(err);
});
if(data) {
req.write(d);
}
req.end();
});
}
let apiKey = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
(async () => {
let resp = await makeRequest("https://api.apitemplate.io/v1/list-objects","GET",apiKey);
let ret = JSON.parse(resp);
console.log(ret);
})();
The above command returns JSON structured like this:
{
"status":"success",
"num_of_records": 3,
"limit": 500,
"offset": 0,
"objects":[
{
"transaction_ref":"9e28f9869-3579-4018-a30d-c38b99a31c6f",
"template_id":"95877b2b1879223e",
"description":null,
"source":"zapier",
"transaction_type":"PDF",
"primary_url":"https://pub-cdn.apitemplate.io/2021/05/9e28f9869-3579-4018-a30d-c38b99a31c6f.jpeg",
"secondary_url":"https://pub-cdn.apitemplate.io/2021/05/9e28f9869-3579-4018-a30d-c38b99a31c6f.png",
"deleted_at":null,
"deletion_status":0,
"created_at":"2021-05-14T07:03:05.065Z"
},
{
"transaction_ref":"ee0d9ba3-6574-40b1-85e1-3e1e8c903aca",
"template_id":"95877b2b1879223e",
"description":null,
"source":"Integromat",
"transaction_type":"PDF",
"primary_url":"https://pub-cdn.apitemplate.io/2021/05/ee0d9ba3-6574-40b1-85e1-3e1e8c903aca.pdf",
"secondary_url":null,
"deleted_at":null,
"deletion_status":0,
"created_at":"2021-05-14T00:00:57.965Z"
},
{
"transaction_ref":"f3df0d9b-373c-8325-a561-232b9bbaeb2e",
"template_id":"95877b2b1879223e",
"description":null,
"source":"zapier",
"transaction_type":"PDF",
"primary_url":"https://pub-cdn.apitemplate.io/2021/05/f3df0d9b-373c-8325-a561-232b9bbaeb2e.pdf",
"secondary_url":null,
"deleted_at":null,
"deletion_status":0,
"created_at":"2021-05-13T07:02:16.498Z"
}
]
}
HTTP Request
Option | Description |
---|---|
Method | GET |
URL | https://api.apitemplate.io/v1/list-objects |
Header | X-API-KEY: [API_KEY] |
Query Parameters
Option | Mandatory | Description |
---|---|---|
template_id |
Optional | It can be obtained in the web console |
limit |
Optional | The number of results that are returned, max 500 records |
offset |
Optional | Position of where to start returning data |
Delete an object
Delete a PDF or an image from CDN and mark the transaction as deleted
curl --header "Content-Type: application/json" \
-H 'X-API-KEY: 6fa6g2pdXGIyxHRhVlGh7U5Vhdckt' \
"https://api.apitemplate.io/v1/delete-object?transaction_ref=1618d386-2343-3d234-b9c7-99c82bb9f104"
# Github library https://github.com/APITemplate-io/Python-Integration
import requests, json
def main():
api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt"
response = requests.get(
F"https://api.apitemplate.io/v1/delete-object?transaction_ref=1618d386-2343-3d234-b9c7-99c82bb9f104",
headers = {"X-API-KEY": F"{api_key}"},
)
if __name__ == "__main__":
main()
// https://github.com/APITemplate-io/CSharp-Integration
Coming soon
<?php
function delete_object($api_key, $trans_ref) {
$url = "https://api.apitemplate.io//v1/delete-object?transaction_ref=". $trans_ref;
$headers = array("X-API-KEY: ".$api_key);
$curl = curl_init();
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
if (!$result) {
return null;
}else{
$json_result = json_decode($result, 1);
return $json_result;
}
}
$api_key = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
$trans_ref = "1618d386-2343-3d234-b9c7-99c82bb9f104";
print_r(delete_object($api_key,$trans_ref));
?>
const { http, https } = require('follow-redirects');
var url = require("url");
function makeRequest(urlEndpoint, method, apiKey, data=null) {
let d = "";
if(data!=null) d = JSON.stringify(data);
const uri = url.parse(urlEndpoint);
const proto = uri.protocol === 'https:' ? https : http;
const opts = {
method: method,
headers: {
'Content-Length': d.length,
'Content-Type': 'application/json',
'X-API-KEY': apiKey
}
};
console.log(proto);
console.log(opts);
return new Promise((resolve, reject) => {
const req = proto.request(urlEndpoint, opts, (res) => {
res.setEncoding('utf8');
let responseBody = '';
res.on('data', (chunk) => {
responseBody += chunk;
});
res.on('end', () => {
resolve(responseBody);
});
});
req.on('error', (err) => {
reject(err);
});
if(data) {
req.write(d);
}
req.end();
});
}
let apiKey = "6fa6g2pdXGIyxHRhVlGh7U5Vhdckt";
let trans_ref = "1618d386-2343-3d234-b9c7-99c82bb9f104";
(async () => {
let resp = await makeRequest("https://api.apitemplate.io//v1/delete-object?transaction_ref=" + trans_ref,"GET",apiKey);
let ret = JSON.parse(resp);
console.log(ret);
})();
The above command returns JSON structured like this:
{
"status":"success",
"transaction_ref":"1618d386-2343-3d234-b9c7-99c82bb9f104"
}
HTTP Request
Option | Description |
---|---|
Method | GET |
URL | https://api.apitemplate.io/v1/delete-object |
Header | X-API-KEY: [API_KEY] |
Query Parameters
Option | Mandatory | Description |
---|---|---|
transaction_ref |
Mandatory | Object transaction reference |
Errors
A success message
{
"status" : "success
}
An error message
{
"status" : "error",
"message": "Invalid api key"
}
Aside the returning message, we use 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. |