Skip to content

About

Go client for the DocSpring API (docspring.com)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DocSpring Go SDK

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

The code in this repository is generated from DocSpring's OpenAPI spec (About this SDK). Issues and pull requests are welcome.

Version 4.0.0. Requires Go 1.23 or later.

Install and configure

Install the package:

go get github.com/docspring/docspring-go/v4

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

Import and initialize the client:

import (
  client "github.com/docspring/docspring-go/v4"
)

apiClient := client.NewClient("", "")

Or provide credentials directly:

apiClient := client.NewClient("API_TOKEN_ID", "API_TOKEN_SECRET")

Generate a PDF

Fill a template with data (use your template's ID in place of tpl_1234567890abcdef01):

templateID := "tpl_1234567890abcdef01"
body := client.CreateSubmissionRequest{
	Data:     map[string]interface{}{"first_name": "John", "last_name": "Smith", "phone_number": "+11234567890"},
	Metadata: map[string]interface{}{"user_id": 42},
	Test:     client.PtrBool(true),
}
request := apiClient.CreateSubmission(context.Background(), templateID).Body(body)
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 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.

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()).

Methods

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
CopyTemplate Copy a template
CreateCombinedPdf Combine PDFs
CreateCustomFileFromUpload Create a custom file from an upload
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
CreateWebhook Create a webhook
DeleteCustomFile Delete a custom file
DeleteFolder Delete a folder
DeleteTemplate Delete a template
DeleteWebhook Delete a webhook
ExpireCombinedPdf Expire a combined PDF
ExpireSubmission Expire a submission
GenerateSubmissionPreview Generate a preview PDF
GetCombinedPdf Get a combined PDF
GetCustomFile Get a custom file
GetFolder Get a folder
GetPresignUrl Get a presigned URL to upload a file
GetSignatureRequest Get a signature request
GetSubmission Get a submission
GetSubmissionBatch Get a batch
GetTemplate Get a template
GetTemplateModelCode Generate typed code for a template's submission data
GetTemplateSchema Get the JSON Schema of a template's submission data
GetWebhook Get a webhook
ListCombinedPdfs List combined PDFs
ListCustomFiles List custom files
ListFolders List folders
ListSubmissions List submissions
ListTemplates List templates
ListTemplateSubmissions List a template's submissions
ListWebhooks List webhooks
MoveFolder Move a folder
MoveTemplate Move a template to a folder
PublishTemplateVersion Publish a template version
RenameFolder Rename a folder
RestoreTemplateVersion Restore a template version
TestAuthentication Test authentication
UpdateSignatureRequest Update a signature request
UpdateTemplate Update a template
UpdateTemplateDocument Replace a template's PDF
UpdateWebhook Update a webhook
UploadTemplate Create a PDF template from an uploaded PDF
UploadTemplateDocument Replace a template's PDF with an uploaded PDF

Errors

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.

The client checks each request against the API's request schemas before sending it. For a request the API would reject, Execute() returns a *client.ValidationError without sending it: its Details have a Code, a Message and a Pointer into the body (or a Parameter). Set SkipRequestValidation on the Configuration to turn the check off. 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 keeps a response field added to the API after this release in its AdditionalProperties map. The objects defined inside a model, such as a template's document, leave it out.
  • Enum values in responses are strings, so a value added to the API after this release comes back as it is: 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 Go generator:

  • Models don't reject a response field added to the API after this release. Stock OpenAPI Generator decodes them with DisallowUnknownFields.
  • An enum value added to the API after this release decodes as the API sent it, instead of failing the whole response. IsValid() says whether it's one this release knows.

On top of the generated code, we add:

  • A client constructor that reads your credentials, region and host from the environment.

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.

About

Go client for the DocSpring API (docspring.com)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages