Notes for AI coding agents working with the DocSpring Go SDK (github.com/docspring/docspring-go/v4): integrating it into an
app, or working in this repository.
Every file here is generated from DocSpring's OpenAPI spec by DocSpring's fork of OpenAPI Generator, and each release replaces all of it. Don't patch an installed copy: the next release overwrites the change. Issues and pull requests are welcome at https://github.com/DocSpring/docspring-go (or email support@docspring.com), and DocSpring makes the fix in the generator so that every release keeps it.
- README.md: install, configuration, an example and how errors and API changes are handled.
- docs/ClientAPI.md: every method, with its parameters and return type.
- docs/: every model and its fields.
- https://docspring.com/docs/llms.txt: DocSpring's documentation for LLMs (
llms-small.txt,llms-full.txt). - https://docspring.com/docs/: the guides. https://docspring.com/docs/api/: the API reference, with Go code for every method.
- https://docspring.com/api-docs/v2/openapi.json: the OpenAPI spec this SDK is generated from.
- Credentials come from
DOCSPRING_TOKEN_IDandDOCSPRING_TOKEN_SECRET(an API token from https://app.docspring.com/api_tokens). Keep them in the environment or a secret store, never in code. An account in the EU region also needsDOCSPRING_REGION=EU. - Call DocSpring from your server. The token secret gives full access to the account, so it must never reach a browser or a mobile app. Signers use signing links or the embedded signing form instead (see Signature requests).
TestAuthenticationchecks the credentials.
- Read a template's data shape before writing the request:
GetTemplateSchemareturns the JSON Schema of its submission data (its field names and types), andGetTemplateModelCodegenerates typed code for it. The keys ofdataare the template's field names. Date fields takeYYYY-MM-DD. - Template IDs look like
tpl_...and submission IDs likesub_.... Store the submission ID with your own record. - Pass
test: truewhile you build: test PDFs are free and watermarked. Live PDFs use credits. - A submission uses the template's latest published version (its draft when nothing has been published yet). Pass
version(draft,1.2.0, or1for the latest 1.x.x) to use another one. CreateSubmissionwaits for the PDF, for up to 95 seconds, and returns the submission in its final state: check itsstate(processed, or a failure state with anerror_message). If the PDF takes longer, the call fails with a 504polling_timeouterror that has the submission's ID. The submission exists and is still being made, so don't send the request again (that makes a second one): get it withGetSubmissionuntil its state isn'tpending. For slow templates or many PDFs, setwaitto false and use webhooks (https://docspring.com/docs/api-guide/synchronous-requests/).CreateSubmissionBatchsends up to 50 submissions in one request.files.pdf.download_urlis a temporary link. Keep the submission ID (orfiles.pdf.permanent_url, which needs your API token) and get a fresh link when someone downloads the PDF.- Submission data is often personal data: don't log request or response bodies.
expires_indeletes a submission's PDF and data that many seconds after it's created, andExpireSubmissiondeletes them now.
Execute()returns anerror. For an error response it's a*client.GenericOpenAPIError:Body()is the raw body andModel()the decoded error, and the*http.ResponsethatExecute()also returns has the status code.- Every error response has one body:
{"error": {"code", "message", "details", "request_id"}}. Branch oncode, not on the message. Each detail has apointerto the request body value it's about, or the queryparameter. - 422
invalid_data: the data doesn't match the template. The submission is saved anyway, asinvalid_data, and the error has itssubmission_id. - 402
insufficient_credits: the submission is saved and is made automatically once the account has credits. Don't send it again (https://docspring.com/docs/api-guide/credits-and-rate-limits/). - 429
rate_limited: wait for the seconds in theRetry-Afterheader, then retry. - Requests are checked against the API's request schemas before they're sent. For a request the API would reject,
Execute()returns a*client.ValidationErrorwithout sending it: itsDetailshave aCode, aMessageand aPointerinto the body (or aParameter). SetSkipRequestValidationon theConfigurationto turn the check off.
- Webhooks tell your server when a submission is processed or fails, instead of polling (https://docspring.com/docs/webhooks/overview/). A webhook created with API v2 sends events in API v2's format (version 4).
- Verify each request's
X-DocSpring-Signatureheader before acting on it: an HMAC-SHA256 of{t}.{raw body}with the webhook's signing secret, computed over the raw body exactly as received (https://docspring.com/docs/webhooks/verifying-signatures/). - No webhook is sent when a submission starts waiting for credits.
- To have people fill in fields and sign before the PDF is made, create the submission with
signature_requests. Each one has thefieldsits signer fills in (a field belongs to one signature request), and theirnameandemail. The PDF is made when every signer has finished (https://docspring.com/docs/api-guide/create-signature-requests/). - Send a signer to the
signature_request_urlof a token fromCreateSignatureRequestToken. Anapitoken's link opens the form for 24 hours and anemailtoken's for 7 days (expires_at), so create a new token when a signer comes back later. - To show the signing form on your own site, use Signature Requests JS, and add the site's domain to the template's Embed Domains (https://docspring.com/docs/guides/embedded-forms/embedded-signature-requests/).
- List methods return
dataandnext_cursor: passnext_cursorascursorto get the next page. - Responses can be newer than this SDK, because DocSpring adds fields and enum values to API v2 without a new
version. The model keeps a response field added to the API after this release in its
AdditionalPropertiesmap. The objects defined inside a model, such as a template'sdocument, leave it out. Enum values in responses are strings, so a value added after this release comes back as it is: handle values you don't recognize. - Optional fields are pointers. Set them with the helpers
client.PtrString,client.PtrInt32,client.PtrBooland so on, and read them with the model's getters (GetDownloadUrl()).