The official TypeScript client for the DocSpring API. DocSpring fills PDF templates with your data, generates PDFs from HTML templates, combines PDFs and collects e-signatures.
Documentation · API reference · npm · Changelog
Version 3.2.0.
Add docspring-ts to your package.json:
npm install docspring-ts --saveOr with Yarn:
yarn add docspring-tsConfigure authentication via environment variables:
export DOCSPRING_TOKEN_ID="API_TOKEN_ID"
export DOCSPRING_TOKEN_SECRET="API_TOKEN_SECRET"You can also configure the region or host. The host takes priority over the region:
export DOCSPRING_REGION="US" # US or EU (defaults to US)
export DOCSPRING_HOST="docspring.yourcompany.com" # For on-premise deploymentsInitialize the DocSpring client with no arguments:
import * as DocSpring from "docspring-ts";
const apiInstance = new DocSpring.Client();Or provide credentials (and optionally a region or host) directly. A host (including DOCSPRING_HOST) is used before
a region:
import * as DocSpring from "docspring-ts";
const apiInstance = new DocSpring.Client({
apiTokenId: "API_TOKEN_ID",
apiTokenSecret: "API_TOKEN_SECRET",
region: "EU",
});Fill a template with data (use your template's ID in place of tpl_1234567890abcdef01):
const templateId = 'tpl_1234567890abcdef01'
const submission = {
data: {
first_name: 'John',
last_name: 'Smith',
phone_number: '+11234567890',
},
metadata: { foo: 123, bar: 'baz' },
}
const result = await apiInstance.generatePdf(templateId, submission)
console.log(result)By default the call waits for the PDF, for up to 95 seconds, and the submission in the response has its
download_url. Set wait to false to get a pending submission straight away.
Sync vs. async processing covers the time limit, status
checks and webhooks.
Client.md has each method's parameters and return type, and models/ has the models. The API reference has TypeScript code for every method.
| Method | Description |
|---|---|
addFieldsToTemplate |
Add new fields to a Template |
batchGeneratePdfs |
Generate multiple PDFs |
combinePdfs |
Merge submission PDFs, template PDFs, or custom files |
copyTemplate |
Copy a template |
createCustomFileFromUpload |
Create a new custom file from a cached S3 upload |
createDataRequestEvent |
Create a new event for emailing a signee a request for signature |
createDataRequestToken |
Create a new data request token for form authentication |
createFolder |
Create a folder |
createHtmlTemplate |
Create a new HTML template |
createPdfTemplate |
Create a new PDF template with a form POST file upload |
createPdfTemplateFromUpload |
Create a new PDF template from a cached S3 file upload |
createWebhook |
Create a webhook |
deleteFolder |
Delete a folder |
deleteTemplate |
Delete a template |
deleteWebhook |
Delete a webhook |
expireCombinedSubmission |
Expire a combined submission |
expireSubmission |
Expire a PDF submission |
generatePdf |
Generate a PDF |
generatePreview |
Generate a preview PDF for partially completed data requests |
getCombinedSubmission |
Check the status of a combined submission (merged PDFs) |
getDataRequest |
Look up a submission data request |
getFullTemplate |
Fetch the full attributes for a PDF template |
getPresignUrl |
Get a presigned S3 URL for direct file upload |
getSubmission |
Check the status of a PDF |
getSubmissionBatch |
Check the status of a submission batch job |
getTemplate |
Check the status of an uploaded template |
getTemplateModelCode |
Generate typed model code for a template |
getTemplateSchema |
Fetch the JSON schema for a template |
getWebhook |
Get a webhook |
listCombinedSubmissions |
Get a list of all combined submissions |
listFolders |
Get a list of all folders |
listSubmissions |
List all submissions |
listTemplates |
Get a list of all templates |
listTemplateSubmissions |
List all submissions for a given template |
listWebhooks |
Get a list of all webhooks |
moveFolderToFolder |
Move a folder |
moveTemplateToFolder |
Move Template to folder |
publishTemplateVersion |
Publish a template version |
renameFolder |
Rename a folder |
restoreTemplateVersion |
Restore a template version |
testAuthentication |
Test authentication |
updateDataRequest |
Update a submission data request |
updateTemplate |
Update a Template |
updateTemplateDocument |
Update a template's document with a form POST file upload |
updateTemplateDocumentFromUpload |
Update a template's document with a cached S3 file upload |
updateWebhook |
Update a webhook |
Methods return a promise that rejects with DocSpring.ApiException for an error response, with the HTTP status in code and the parsed body in body.
DocSpring adds fields and enum values to API v1 without releasing a new API version. Changes that would break existing code, such as removing or renaming a field, go in a new API version (API changes). So this SDK keeps working with responses that are newer than it is:
- The model leaves out a response field added to the API after this release.
- An enum value added to the API after this release comes back as a string, even though the type lists only the values this release knows, so handle values you don't recognize.
Upgrade the SDK to read new fields and enum values. The changelog lists what each release adds.
This SDK is generated from DocSpring's OpenAPI spec with DocSpring's fork of OpenAPI Generator 7.16.0. The fork changes the TypeScript generator:
nameMappingsapply to property names, so the JSON schema model's$idbecomesschema_idinstead of clashing withid.
On top of the generated code, we add:
- A client constructor that reads your credentials, region and host from the environment.
Because the code is generated, we can't merge pull requests that change it. Please open an issue or email support@docspring.com instead, and we'll fix it in the generator. AGENTS.md is a short guide for AI coding agents.
MIT. See LICENSE.