Try it live: Retrieve Template by ID → API Tester — send a real request from your browser.
GET /v1/pdf/documentparser/templates/:id
Use the PDF.co dashbaord to manage your Document Parser Templates.
Please refer to the Document Parser Template Editor and PDF.co Document Parser: Template Creation Guide for more information.
Query parameters
No query parameters accepted.Responses
| Parameter | Type | Description |
|---|---|---|
id | integer | Unique identifier for the template |
type | string | Source of the template. The available sources are: user, system. |
title | string | Title of the template |
description | string | Description of what the template does |
created_at | String (ISO 8601) | Timestamp indicating when the template was initially created |
updated_at | String (ISO 8601) | Timestamp indicating the last time the template was modified |
body | string | Template content |
credits | integer | Number of credits consumed by the request |
remainingCredits | integer | Number of credits remaining in the account |
Inconsistent URL Encoding in cURL Output: When using cURL to make API requests, the output JSON may show URL characters encoded as Unicode escape sequences. For example, the ampersand character (
&) may appear as \u0026 in the cURL output. This is normal JSON encoding behavior and does not affect the validity of the URL. The URL will function correctly when used, as JSON parsers automatically decode these escape sequences. If you’re parsing the response programmatically, your JSON parser will handle this conversion automatically.Code Samples
- CURL
- JavaScript/Node.js
- Python
- C#
- Java
- PHP
curl --location --request GET 'https://api.pdf.co/v1/pdf/documentparser/templates/1' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {{x-api-key}}' \
--data-raw ''
var https = require("https");
var fs = require("fs");
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
const API_KEY = "***********************************";
// Template ID to retrieve
const TemplateId = 1;
// Destination JSON file name
const DestinationFile = "./template.json";
// Prepare request to `Retrieve Template by ID` API endpoint
var queryPath = `/v1/pdf/documentparser/templates/${TemplateId}`;
var reqOptions = {
host: "api.pdf.co",
method: "GET",
path: queryPath,
headers: {
"x-api-key": API_KEY
}
};
// Send request
https.get(reqOptions, (response) => {
let chunks = [];
response.on("data", (d) => {
chunks.push(d);
});
response.on("end", () => {
var result = Buffer.concat(chunks).toString("utf8");
// Parse JSON response
var data = JSON.parse(result);
if (!data.error) {
fs.writeFileSync(DestinationFile, result);
console.log(`Template JSON saved as "${DestinationFile}" file.`);
}
else {
// Service reported error
console.log(data.message);
}
});
}).on("error", (e) => {
// Request error
console.log(e);
});
import requests # pip install requests
# The authentication key (API Key).
# Get your own by registering at https://app.pdf.co
API_KEY = "*************************************"
# Base URL for PDF.co Web API requests
BASE_URL = "https://api.pdf.co/v1"
# Template ID to retrieve
TemplateId = 1
# Destination JSON file name
DestinationFile = ".\\template.json"
def main(args = None):
getTemplate(TemplateId, DestinationFile)
def getTemplate(templateId, destinationFile):
"""Retrieves a Document Parser template by ID using PDF.co Web API"""
# Prepare URL for 'Retrieve Template by ID' API request
url = "{}/pdf/documentparser/templates/{}".format(BASE_URL, templateId)
# Execute request and get response as JSON
response = requests.get(url, headers={ "x-api-key": API_KEY })
if (response.status_code == 200):
json = response.json()
if json.get("error"):
# Show service reported error
print(json["message"])
else:
with open(destinationFile, 'w', encoding='utf-8') as file:
file.write(response.text)
print(f"Template JSON saved as \"{destinationFile}\" file.")
else:
print(f"Request error: {response.status_code} {response.reason}")
if __name__ == '__main__':
main()
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Net;
namespace PDFcoApiExample
{
class Program
{
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
const String API_KEY = "***********************************";
// Template ID to retrieve
const int TemplateId = 1;
// Destination JSON file name
const string DestinationFile = @".\template.json";
static void Main(string[] args)
{
// Create standard .NET web client instance
WebClient webClient = new WebClient();
// Set API Key
webClient.Headers.Add("x-api-key", API_KEY);
// URL of `Retrieve Template by ID` API call
string url = string.Format("https://api.pdf.co/v1/pdf/documentparser/templates/{0}", TemplateId);
try
{
// Execute GET request
string response = webClient.DownloadString(url);
// Parse JSON response
JObject json = JObject.Parse(response);
if (json["error"] == null || json["error"].ToObject<bool>() == false)
{
// Save template JSON body
File.WriteAllText(DestinationFile, response);
Console.WriteLine("Template JSON saved as \"{0}\" file.", DestinationFile);
}
else
{
Console.WriteLine(json["message"].ToString());
}
}
catch (WebException e)
{
Console.WriteLine(e.ToString());
}
webClient.Dispose();
Console.WriteLine();
Console.WriteLine("Press any key...");
Console.ReadKey();
}
}
}
package com.company;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import okhttp3.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main
{
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
final static String API_KEY = "***********************************";
public static void main(String[] args) throws IOException
{
// Template ID to retrieve
final int TemplateId = 1;
// Destination JSON file name
final Path DestinationFile = Paths.get(".\\template.json");
// Create HTTP client instance
OkHttpClient webClient = new OkHttpClient();
// Prepare URL for `Retrieve Template by ID` API call
String query = String.format(
"https://api.pdf.co/v1/pdf/documentparser/templates/%s",
TemplateId);
// Prepare request
Request request = new Request.Builder()
.url(query)
.addHeader("x-api-key", API_KEY) // (!) Set API Key
.addHeader("Content-Type", "application/json")
.build();
// Execute request
Response response = webClient.newCall(request).execute();
if (response.code() == 200)
{
String result = response.body().string();
// Parse JSON response
JsonObject json = new JsonParser().parse(result).getAsJsonObject();
boolean error = json.has("error") && json.get("error").getAsBoolean();
if (!error)
{
// Save template JSON body
OutputStream output = new FileOutputStream(DestinationFile.toFile());
output.write(result.getBytes(StandardCharsets.UTF_8));
output.flush();
output.close();
System.out.printf("Template JSON saved as \"%s\" file.", DestinationFile.toString());
}
else
{
// Display service reported error
System.out.println(json.get("message").getAsString());
}
}
else
{
// Display request error
System.out.println(response.code() + " " + response.message());
}
}
}
<?php
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
$API_KEY = "***********************************";
// Template ID to retrieve
$TemplateId = 1;
// Optional destination file. Leave empty to print JSON to stdout.
$DestinationFile = "./template.json";
getTemplate($API_KEY, $TemplateId, $DestinationFile);
function getTemplate($apiKey, $templateId, $destinationFile)
{
// Prepare URL for `Retrieve Template by ID` API call
$url = "https://api.pdf.co/v1/pdf/documentparser/templates/" . $templateId;
// Create request
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-api-key: " . $apiKey, "Content-Type: application/json"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Execute request
$result = curl_exec($curl);
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$curlError = curl_error($curl);
curl_close($curl);
if ($result === false) {
// Display CURL error
echo "getTemplate(): " . $curlError . PHP_EOL;
return;
}
if ($statusCode != 200) {
// Display request error
echo "getTemplate(): request error " . $statusCode . PHP_EOL . $result . PHP_EOL;
return;
}
$json = json_decode($result, true);
if (!empty($json["error"])) {
// Display service reported error
echo "getTemplate(): " . $json["message"] . PHP_EOL;
return;
}
if ($destinationFile !== "") {
if (file_put_contents($destinationFile, $result) === false) {
echo "getTemplate(): unable to create " . $destinationFile . PHP_EOL;
return;
}
echo "Template JSON saved as \"" . $destinationFile . "\" file." . PHP_EOL;
} else {
echo $result . PHP_EOL;
}
}
?>