A digital signature shows who signed a PDF and that it has not been changed since. The Sign tool signs a PDF with a certificate that belongs to you. You can store the certificate once in your account and choose it each time, so its private key is not sent with every request.
What you need
- A signing certificate and its private key, both as PEM text. The private key must be without a passphrase.
- A plan that includes the Sign tool (see the Capabilities page in the Dashboard, A tour of the Dashboard).
Store a certificate
In Studio, open the Sign PDF tool and choose to manage your signing certificates. Give it a name, paste or load the certificate and the private key, and store it. The window then lists each certificate by name, subject and expiry date. It never shows a private key again.
With the API, send the same three values:
curl -X POST "https://app.h2i.davixlabs.io/v1/certificates" \
-H "X-Api-Key: $DAVIX_H2I_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Office stamp", "certPem": "-----BEGIN CERTIFICATE-----...", "keyPem": "-----BEGIN PRIVATE KEY-----..."}'
The answer describes the certificate (id, name, subject, issuer, SHA-256 fingerprint, validity dates, when it was last used). The private key is stored encrypted and is never returned.
Sign a PDF
curl -X POST "https://app.h2i.davixlabs.io/v1/pdfs/sign" \
-H "X-Api-Key: $DAVIX_H2I_API_KEY" \
-F 'file=@contract.pdf' \
-F 'certificateId=12' \
-F 'reason=Approved' \
-F 'signerName=Jane Smith'
Use certificateId for a stored certificate. You can also send certPem and keyPem in the request instead, but then the private key travels with every call. The optional reason, signerName, contactInfo and location are written into the signature.
List and delete certificates
GET /v1/certificateslists your certificates, andGET /v1/certificates/{id}shows one.DELETE /v1/certificates/{id}deletes a certificate and its private key. You can only see and delete your own; anything else answersnot_found.
Certificates are part of your account, so they are also removed if you delete your account (How long we keep your files).
Errors
duplicate_certificate_name: you already have a certificate with that name.certificate_limit_reached: you stored as many certificates as allowed.certificates_unavailable: storing certificates is not available right now. Try again later or contact support.
The other codes are in Error codes and rate limits. More PDF tools: Merge, split and rotate PDFs.
Try it in your language
Choose a tool and a language. The parameters are filled in for you and always match the current API.
cURL
curl -X POST "https://app.h2i.davixlabs.io/v1/pdfs/sign" \
-H "X-Api-Key: $DAVIX_H2I_API_KEY" \
-F 'file=@document.pdf' \
-F 'certificateId=1' \
-F 'output_bundle=zip' \
-F 'response=url'Node.js
const { DavixH2I } = require('@davixlabs/h2i-sdk');
const h2i = new DavixH2I({ apiKey: process.env.DAVIX_H2I_API_KEY, baseUrl: process.env.DAVIX_H2I_URL });
const result = await h2i.pdfs.sign({
"file": 'document.pdf',
"certificateId": 1,
"output_bundle": "zip",
"response": "url"
});
console.log(result.data, result.requestId);PHP
<?php
require 'vendor/autoload.php';
$h2i = new \Davix\H2I\Client(['apiKey' => getenv('DAVIX_H2I_API_KEY'), 'baseUrl' => getenv('DAVIX_H2I_URL')]);
$result = $h2i->pdfs()->sign([
'file' => 'document.pdf',
'certificateId' => 1,
'output_bundle' => 'zip',
'response' => 'url',
]);
echo $result->requestId;Checked against API contract 3.0.0 and the Studio source code.
