Guide menu · Keys and errors
API guide
Keys and errors
API keys, errors, limits and safe retries.
API keys
#An organization admin creates keys under API and webhooks. A key looks like sc_ followed by 40 letters and digits, and is shown once, when it is created. We keep only a fingerprint of it, so nobody can show it to you again; if it is lost, create a new one.
- A key acts as the admin who created it. Everything it does is in the audit log under that person's name, with the same permissions they have.
- It stops at once when it is revoked, or when that person is removed from the organization.
- Use one key per system, named after it, so you can revoke one without stopping the others.
- Keep keys on your server. Never put one in a web page, a mobile app or a public repository. If one may have leaked, revoke it straight away.
Sending the key
#Send the key on every request, in the Authorization header, after the word Bearer. Without a valid key the answer is 401 with a WWW-Authenticate: Bearer header.
Also send Accept: application/json, so every answer, including errors, is JSON.
Request
curl 'https://truesealed.com/api/v1/templates' \
-H "Authorization: Bearer $SEALCHECK_API_KEY" \
-H 'Accept: application/json'
<?php
require 'vendor/autoload.php'; // composer require guzzlehttp/guzzle
$client = new GuzzleHttp\Client([
'base_uri' => 'https://truesealed.com/api/v1/',
'headers' => [
'Authorization' => 'Bearer '.getenv('SEALCHECK_API_KEY'),
'Accept' => 'application/json',
],
]);
$response = $client->get('templates');
$result = json_decode((string) $response->getBody(), true);
// Node.js 18 or later
const response = await fetch('https://truesealed.com/api/v1/templates', {
headers: {
Authorization: `Bearer ${process.env.SEALCHECK_API_KEY}`,
Accept: 'application/json',
},
});
const result = await response.json();
import os
import requests # pip install requests
response = requests.get(
"https://truesealed.com/api/v1/templates",
headers={
"Authorization": f"Bearer {os.environ['SEALCHECK_API_KEY']}",
"Accept": "application/json",
},
)
result = response.json()
Errors
#The status code tells you what happened. Every error also has a message you can log or show.
200OK- It worked.
201Created- A document was issued.
401Unauthenticated- The key is missing, wrong, revoked, or its owner no longer has access.
403Forbidden- Not allowed. For example, your organization is waiting for verification or is suspended, so it cannot issue.
404Not found- No such document in your organization. Other organizations' documents are never visible.
422Unprocessable- Something in the request needs fixing. errors lists each field.
429Too many requests- Slow down: wait the number of seconds in Retry-After.
500Server error- Something went wrong on our side. Safe to retry with the same Idempotency-Key.
{
"message": "The recipient name field is required.",
"errors": {
"recipient_name": [
"The recipient name field is required."
]
}
}
{
"message": "Send a valid API key in the Authorization header, as \"Bearer\" followed by the key."
}
Rate limits
#Each key may make 120 requests a minute. Past that, the answer is 429 Too Many Requests with a Retry-After header giving the seconds to wait. Every answer carries X-RateLimit-Limit and X-RateLimit-Remaining, so you can slow down before you reach it.
Issuing renders a PDF, which takes a moment. To issue hundreds at once, send requests one or a few at a time, or upload a spreadsheet as a bulk issue in your organization's area and listen for the batch.finished webhook.
Safe retries
#Networks fail. When you issue a document, send an Idempotency-Key header with a value unique to that document in your system, such as an enrolment number. Then retrying is always safe:
- The same key with the same details, within 24 hours, returns the first document with
200andIdempotent-Replayed: true. Nothing new is issued. - The same key with different details is refused with
422, because it is almost certainly a mistake. - Keys are 1 to 255 characters and belong to your organization only.
Revoking needs no Idempotency-Key: if you repeat it, the second attempt answers 422, already revoked, and nothing changes.
Request
curl -X POST 'https://truesealed.com/api/v1/documents' \
-H "Authorization: Bearer $SEALCHECK_API_KEY" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: enrolment-48213' \
-d '{
"recipient_name": "Ada Lovelace",
"recipient_email": "[email protected]",
"title": "Certificate in First Aid",
"template_id": "01m7p0nr39388waqvbw0radjxa",
"expires_at": "2028-03-01",
"fields": {
"grade": "Distinction"
}
}'
<?php
require 'vendor/autoload.php'; // composer require guzzlehttp/guzzle
$client = new GuzzleHttp\Client([
'base_uri' => 'https://truesealed.com/api/v1/',
'headers' => [
'Authorization' => 'Bearer '.getenv('SEALCHECK_API_KEY'),
'Accept' => 'application/json',
],
]);
$response = $client->post('documents', [
'headers' => [
'Idempotency-Key' => 'enrolment-48213',
],
'json' => [
'recipient_name' => 'Ada Lovelace',
'recipient_email' => '[email protected]',
'title' => 'Certificate in First Aid',
'template_id' => '01m7p0nr39388waqvbw0radjxa',
'expires_at' => '2028-03-01',
'fields' => [
'grade' => 'Distinction',
],
],
]);
$result = json_decode((string) $response->getBody(), true);
// Node.js 18 or later
const response = await fetch('https://truesealed.com/api/v1/documents', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SEALCHECK_API_KEY}`,
Accept: 'application/json',
'Content-Type': 'application/json',
'Idempotency-Key': 'enrolment-48213',
},
body: JSON.stringify({
"recipient_name": "Ada Lovelace",
"recipient_email": "[email protected]",
"title": "Certificate in First Aid",
"template_id": "01m7p0nr39388waqvbw0radjxa",
"expires_at": "2028-03-01",
"fields": {
"grade": "Distinction"
}
}),
});
const result = await response.json();
import os
import requests # pip install requests
response = requests.post(
"https://truesealed.com/api/v1/documents",
headers={
"Authorization": f"Bearer {os.environ['SEALCHECK_API_KEY']}",
"Accept": "application/json",
"Idempotency-Key": "enrolment-48213",
},
json={
"recipient_name": "Ada Lovelace",
"recipient_email": "[email protected]",
"title": "Certificate in First Aid",
"template_id": "01m7p0nr39388waqvbw0radjxa",
"expires_at": "2028-03-01",
"fields": {
"grade": "Distinction",
},
},
)
result = response.json()
Pagination
#Lists come one page at a time, newest first. Choose the size with per_page (1 to 100, default 25), and follow links.next until it is null. meta.total tells you how many there are in all.
{
"meta": {
"current_page": 1,
"last_page": 6,
"per_page": 1,
"total": 6
},
"links": {
"next": "https://truesealed.com/api/v1/documents?status=valid&per_page=1&page=2",
"prev": null
}
}
Changes to the API
#This is version 1, in the address as /api/v1. New fields may appear in answers and new events in webhooks, so ignore any you do not know rather than failing on them. A change that could break your code would come as a new version, at a new address.