The official Go 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 · pkg.go.dev · Changelog
Version 3.2.0. Requires Go 1.23 or later.
Install the package:
go get github.com/docspring/docspring-go/v3Configure 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 deploymentsImport and initialize the client:
import (
client "github.com/docspring/docspring-go/v3"
)
apiClient := client.NewClient("", "")Or provide credentials directly:
apiClient := client.NewClient("API_TOKEN_ID", "API_TOKEN_SECRET")Fill a template with data (use your template's ID in place of tpl_1234567890abcdef01):
templateID := "tpl_1234567890abcdef01"
submission := client.CreatePdfSubmissionData{Data: map[string]interface{}{"first_name": "John", "last_name": "Smith", "phone_number": "+11234567890"}, Metadata: map[string]interface{}{"foo": 123, "bar": "baz"}}
request := apiClient.GeneratePdf(context.Background(), templateID).Submission(submission)
result, _, err := request.Execute()
if err != nil {
fmt.Println(err)
} else {
fmt.Println(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.
Optional fields are pointers. Set them with the helpers client.PtrString, client.PtrInt32, client.PtrBool and so on, and read them with the model's getters (GetDownloadUrl()).
docs/ClientAPI.md has each method's parameters and return type, and docs/ has the models. The API reference has Go 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 |
Execute() returns an error. For an error response it's a *client.GenericOpenAPIError: Body() is the raw body and Model() the decoded error, and the *http.Response that Execute() also returns has the status code.
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 keeps a response field added to the API after this release in its
AdditionalPropertiesmap. - An enum value added to the API after this release comes back as a string, 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 Go generator:
- Models don't reject a response field added to the API after this release. Stock OpenAPI Generator decodes them with
DisallowUnknownFields.
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.