Making API requests
Making API requests to our SDKs
You can make Inkit API requests by using our Python or Node.js SDKs. This simplifies the process of making API requests. To use an SDK in your application, do the following:
- Install the SDK library in your development environment.
- Import the library into your application.
- Set your API key in the Inkit object so that we can authenticate your request.
- Specify your request parameters in the SDK method you will call.
- Make your API request by invoking the SDK method while storing the response in an object, which you can then process.
Here is an example of how to use our SDKs to generate a document from a template:
# Import the Inkit Python package
import inkit
from inkit.exceptions import InkitResponseException
# Import json package
import json
# Replace the string below with your API key
inkit.api_token = "ENTER YOUR API KEY"
try:
# Create a PDF document from a template
resp = inkit.Render.create(
# Specify the ID of the template
template_id = "ENTER YOUR TEMPLATE ID",
# Specify the data for the Name field
merge_parameters = {"Name": "John"},
# Specify the name of the PDF file
destinations = {"inkit_storage": {"name": "Mail Merge Python SDK"}}
)
# Print the JSON repsonse of the API call
print(json.dumps(resp.data, indent = 3))
except InkitResponseException as err:
# Print any error
print(err.response.data)
// Import the Inkit Node.js package
const Inkit = require("inkit");
// Replace the string below with your API key
Inkit.apiToken = "ENTER YOUR API KEY";
// Call the PDF renderer
createRender();
// Create a PDF document from a template
async function createRender() {
try {
const result = await Inkit.Render.create({
// Specify the ID of the template
templateId: 'ENTER YOUR TEMPLATE ID',
// Specify the data for the Name field
mergeParameters: {"Name": "John"},
// Specify the name of the PDF file
destinations: {"inkit_storage": {"name": "Mail Merge Node.js SDK"}}
});
// Print the JSON response of the API call
console.log(JSON.stringify(result.data, null, 3));
} catch (error) {
// Print any error
console.error(error.response.status, error.response.statusText);
}
}
Making API requests to our endpoint URLs
Making API requests to our endpoint URLs in the API reference
Our API reference is a convenient tool for making Inkit API requests to our endpoint URLs. You can also other tools that let you make API requests, such as cURL and Pipedream.
To make Inkit API requests in the API reference, do the following:
-
Select the Inkit API request in the left sidebar. Here we will select the Retrieve Document Information URL.
-
Enter your API key in the X-Inkit-API-Token field in the HEADERS section.
-
Enter the request parameters in the PARAMS sections. Here we will enter the ID of the document we want information on.
-
To execute the request, click the Try It! button in the REQUEST panel.
-
The response will display in the RESPONSE panel.
Making API requests to our endpoint URLs in code
If you develop your applications in languages other than the ones supported by our SDKs, you can make Inkit API requests by issuing them to our endpoint URLs in your code. To use endpoint URLs in your application, do the following:
- Set your API key in the request header so that we can authenticate your request.
- Specify your request parameters in the request body.
- Make your API request while storing the response in an object, which you can then process.
Like when making API requests to our SDK, the following example generates a document from a template, but it does so by making requests to our Generate endpoint URL:
# Import json and requests package
import json
import requests
# Set the headers
HEADERS = {
"accept": "application/json",
"Content-Type": "application/json",
"X-Inkit-API-Token": "ENTER YOUR API KEY"
}
# Set the Inkit Generate endpoint URL
INKIT_URL = "https://api.inkit.com/v1/generate"
# Create a body JSON object
BODY = {
"merge_parameters": {"Name": "John"},
"destinations": {"inkit_storage": {"name": "Mail Merge URL Endpoint"}},
"template_id": "ENTER YOUR TEMPLATE ID"
}
# Pass the body object to the Generate endpoint
try:
json_response = requests.request("POST", INKIT_URL, headers=HEADERS, data=json.dumps(BODY)).json()
except requests.exceptions.RequestException as err:
# Print any error
raise SystemExit(err)
# Print the API response in JSON format
print(json.dumps(json_response, indent = 3))
Updated 10 months ago