docspring / docspring
Use DocSpring's API to fill PDF forms, generate PDFs and Word documents from HTML or Word templates, merge PDFs, and request legally binding e-signatures.
Requires
- php: ^8.1
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^7.3
- guzzlehttp/psr7: ^1.7 || ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.5
- phpunit/phpunit: ^8.0 || ^9.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The official PHP client for the DocSpring API. DocSpring fills PDF forms with your data, generates PDFs and Word documents from HTML and Word templates, combines PDFs and collects e-signatures.
Documentation · API reference · Packagist · Changelog
The code in this repository is generated from DocSpring's OpenAPI spec (About this SDK). Issues and pull requests are welcome.
Outside PHP code, the DocSpring CLI calls the same API from a terminal or a shell script, and the MCP server connects AI assistants to your account.
Version 4.8.0. Requires PHP ^8.1.
Install and configure
Install via Composer:
composer require docspring/docspring
Or add to your composer.json:
{
"require": {
"docspring/docspring": "*"
}
}
Then run:
composer install
Configure 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 deployments
Initialize the client:
require 'vendor/autoload.php'; $config = DocSpring\Configuration::getDefaultConfiguration(); $api = new DocSpring\Api\Client(null, $config);
Or provide credentials directly:
require 'vendor/autoload.php'; $config = DocSpring\Configuration::getDefaultConfiguration(); $config->setUsername('API_TOKEN_ID'); $config->setPassword('API_TOKEN_SECRET'); $api = new DocSpring\Api\Client(null, $config);
Generate a PDF
Fill a template with data (use your template's ID in place of tpl_1234567890abcdef01):
$templateId = 'tpl_1234567890abcdef01'; $body = [ 'data' => [ 'first_name' => 'John', 'last_name' => 'Smith', 'phone_number' => '+11234567890' ], 'metadata' => [ 'user_id' => 42 ], 'test' => true ]; $result = $api->createSubmission( $templateId, $body ); echo json_encode($result, JSON_PRETTY_PRINT) . "\n";
By default the call waits for the PDF, for up to 95 seconds, and the submission in the response has a link to
download it (files.pdf.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.
Methods
docs/Api/Client.md has each method's parameters and return type, and docs/Model/ has the models. The API reference has PHP code for every method.
| Method | Description |
|---|---|
addPageNumbers |
Add page numbers |
addTemplateFields |
Add fields to a template |
askSupportHelp |
Ask for help |
compressPdf |
Compress a PDF |
copyTemplate |
Copy a template |
createAccountEmailAction |
Create an account email action |
createCombinedPdf |
Combine PDFs |
createCustomFileFromUpload |
Create a custom file from an upload |
createEmailAction |
Create an email action |
createEmailDomain |
Add an email domain |
createFolder |
Create a folder |
createSignatureRequestEvent |
Record a signature request event |
createSignatureRequestToken |
Create a signature request token |
createSubmission |
Generate a PDF |
createSubmissionBatch |
Generate PDFs in a batch |
createTemplate |
Create a template |
createTemplatePreview |
Preview a template with data |
createWebhook |
Create a webhook |
decryptPdf |
Decrypt a PDF |
deleteAccountEmailAction |
Delete an account email action |
deleteCustomFile |
Delete a custom file |
deleteEmailAction |
Delete an email action |
deleteEmailActionCustomization |
Reset an account email action's customization |
deleteEmailDomain |
Remove an email domain |
deleteFolder |
Delete a folder |
deleteJob |
Delete a job |
deleteTemplate |
Delete a template |
deleteWebhook |
Delete a webhook |
encryptPdf |
Encrypt a PDF |
expireCombinedPdf |
Expire a combined PDF |
expireSubmission |
Expire a submission |
extractPages |
Extract pages from a PDF |
flattenPdf |
Flatten a PDF |
generateSubmissionFiles |
Generate more files |
generateSubmissionPreview |
Generate a preview PDF |
getAccountEmailAction |
Get an account email action |
getCombinedPdf |
Get a combined PDF |
getCustomFile |
Get a custom file |
getEmailAction |
Get an email action |
getEmailDomain |
Get an email domain |
getFolder |
Get a folder |
getJob |
Get a job |
getPresignUrl |
Get a presigned URL to upload a file |
getSignatureRequest |
Get a signature request |
getSubmission |
Get a submission |
getSubmissionBatch |
Get a batch |
getSupportHelp |
Get a help request |
getSupportTicket |
Get a support ticket |
getTemplate |
Get a template |
getTemplateDiff |
Compare a version of a template with the one before it |
getTemplateModelCode |
Generate typed code for a template's submission data |
getTemplatePageImages |
Get images of a template's pages |
getTemplatePreview |
Get a template preview |
getTemplateSchema |
Get the JSON Schema of a template's submission data |
getWebhook |
Get a webhook |
htmlToPdf |
Convert HTML to a PDF |
imagesToPdf |
Convert images to a PDF |
listAccountEmailActions |
List account email actions |
listCombinedPdfs |
List combined PDFs |
listCustomFiles |
List custom files |
listEmailActions |
List email actions |
listEmailDomains |
List email domains |
listFolders |
List folders |
listJobs |
List jobs |
listSubmissions |
List submissions |
listSupportTickets |
List support tickets |
listTemplateFields |
List a template's fields |
listTemplates |
List templates |
listTemplateSubmissions |
List a template's submissions |
listWebhooks |
List webhooks |
markdownToPdf |
Convert Markdown to a PDF |
moveFolder |
Move a folder |
moveTemplate |
Move a template to a folder |
openSupportTicket |
Open a support ticket |
pdfToImages |
Render PDF pages as images |
pdfToText |
Extract text from a PDF |
publishTemplateVersion |
Publish a template version |
removeTemplateFields |
Remove fields from a template |
renameFolder |
Rename a folder |
reorderTemplateFields |
Reorder a template's fields |
replyToSupportTicket |
Reply to a support ticket |
restoreTemplateVersion |
Restore a template version |
rotatePages |
Rotate pages |
sendAccountEmailActionTestEmail |
Send a test email for an account email action |
sendEmailActionTestEmail |
Send a test email |
sendSupportFeedback |
Send feedback |
splitPdf |
Split a PDF |
testAuthentication |
Test authentication |
updateAccountEmailAction |
Update an account email action |
updateEmailAction |
Update an email action |
updateEmailActionCustomization |
Customize an account email action for a template |
updateSignatureRequest |
Update a signature request |
updateTemplate |
Update a template |
updateTemplateDocument |
Replace a template's document |
updateTemplateFields |
Update a template's fields |
updateWebhook |
Update a webhook |
uploadTemplate |
Create a template from an uploaded PDF or Word document |
uploadTemplateDocument |
Replace a template's document with an uploaded file |
validateSubmission |
Check a submission without creating it |
verifyEmailDomain |
Verify an email domain |
watermarkPdf |
Watermark a PDF |
Errors
Methods throw DocSpring\ApiException for an error response, with the HTTP status in getCode() and the body in getResponseBody().
The client checks each request against the API's request schemas before sending it. A request the API would reject throws a DocSpring\ValidationException (an InvalidArgumentException), whose getDetails() are arrays with code, message and a pointer into the body (or a parameter). Turn the check off with setValidateRequests(false) on the Configuration.
The details are the ones the API's 422 response would have, so you get them without a round trip.
API changes
DocSpring adds fields and enum values to API v2 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 the API sent it: handle values you don't recognize.
Upgrade the SDK to read new fields and enum values. The changelog lists what each release adds.
About this SDK
This SDK is generated from DocSpring's OpenAPI spec with DocSpring's fork of OpenAPI Generator 7.26.0. The fork changes the PHP generator:
- An enum value added to the API after this release comes back as the API sent it, instead of throwing
InvalidArgumentException, and is kept when the model is serialized again. - A union model (
CombinedPdfSourceInput) keeps thetypeit's given. Stock OpenAPI Generator sets it to the model's name.
On top of the generated code, we add:
- A client constructor that reads your credentials, region and host from the environment.
- Fixes for the file uploads in
uploadTemplateanduploadTemplateDocument. DocSpring\Webhooks::verifyWebhookSignature($payload, $signatureHeader, $secret)checks a webhook request'sX-DocSpring-Signatureheader, with$toleranceand$nowarguments.
Each release regenerates every file, so a change made only here would be lost in the next one. Issues and pull requests are welcome all the same: open an issue or a pull request, or email support@docspring.com, and we'll make the fix in the generator so that every release keeps it. AGENTS.md is a guide for AI coding agents that integrate this SDK.
License
MIT. See LICENSE.