Making API requests

You can make Inkit API requests in two ways, by using one of our SDKs or by making requests to one of our endpoint URLs.

Making API requests to our SDKs

You can make Inkit API requests by using our Python or Node.js SDKs. This simplifies making API requests and processing their responses. To use an SDK in your application, do the following:

  1. Install the SDK library in your development environment.
  2. Import the library into your application.
  3. Set your API key in the Inkit object so that we can authenticate your request.
  4. Specify your request parameters in the SDK method you will call.
  5. 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

You can make Inkit API requests to our endpoint URLs through our API reference (or similar tool) or through code.

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:

  1. Select the Inkit API request in the left sidebar. Here we will select the Retrieve Document Information URL.

  2. Enter your API key in the X-Inkit-API-Token field in the HEADERS section.

  3. Enter the request parameters in the PARAMS sections. Here we will enter the ID of the document we want information on.

  4. To execute the request, click the Try It! button in the REQUEST panel.

  5. 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:

  1. Set your API key in the request header so that we can authenticate your request.
  2. Specify your request parameters in the request body.
  3. Make your API request while storing the response in an object, which you can then process.

Like in the above section, the following example generates a document from a template, but it does so in Ruby by making requests to our endpoint URL:

# Import libraries
require 'uri'
require 'net/http'
require 'json'

# Set the Inkit endpoint URL
url = URI("https://api.inkit.com/v1/generate")

# Build HTTP request
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)

# Set request header
request["accept"] = 'application/json'
request["Content-Type"] = 'application/json'
request["X-Inkit-API-Token"] = 'ENTER YOUR API KEY'

# Set request body
body = {
        "merge_parameters": {"Name": "John"},
        "destinations": {"inkit_storage": {"name": "Mail Merge Ruby"}},
        "template_id": "ENTER YOUR TEMPLATE ID"
       }
# convert body to JSON
request.body = JSON.generate(body)

# Execute request
response = http.request(request)
# Print the JSON repsonse of the API call
puts response.read_body