Skip to content

About

C# API Client for DocSpring

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

DocSpring C# SDK

The official C# 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 · NuGet · Changelog

Version 3.4.0. Requires .NET Standard 2.0 (.NET 6 or later, or .NET Framework 4.6.2 or later).

Install and configure

Install from NuGet:

Package Manager

PM> Install-Package DocSpring.Client

.NET CLI

dotnet add package DocSpring.Client

Paket CLI

paket add DocSpring.Client

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:

var api = DocSpring.Client.Client.EnvClientFactory.NewClient();

Or provide credentials directly:

var api = DocSpring.Client.Client.EnvClientFactory.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):

var templateId = "tpl_1234567890abcdef01";
var submission = new DocSpring.Client.Model.CreatePdfSubmissionData(
  new Dictionary<string, object> {
  { "first_name", "John" },
  { "last_name", "Smith" },
  { "phone_number", "+11234567890" }
}
) {
  metadata = new Dictionary<string, object> {
  { "foo", 123 },
  { "bar", "baz" }
}
};

var task = api.GeneratePdfAsync(templateId, submission: submission);
var resp = await task;
Console.WriteLine(resp);

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.

Methods

docs/apis/Client.md has each method's parameters and return type, and docs/models/ has the models. The API reference has C# 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

Errors

Methods return a response object rather than throwing for an error status. IsCreated, IsUnprocessableContent and the other Is... properties say which documented response came back, and Created() or TryCreated(out var result) give you its body.

API changes

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 (models have an AdditionalProperties dictionary, but the generated JSON converters don't fill it).
  • An enum value added to the API after this release comes back as UnknownDefaultOpenApi, so give each switch over an enum a case or default for it.

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.16.0. The fork changes the C# generator:

  • Enum values added to the API after this release come back as UnknownDefaultOpenApi instead of throwing, for required and nullable enums.
  • Nullable enums read and write null without throwing.
  • File uploads send a multipart/form-data body with the file's name and boundary.
  • Paths with a query string (?endpoint_variant=...) aren't percent-encoded into the path.
  • Model constructors assign required properties, and optional object and list properties serialize their value rather than the Option<T> wrapper.

On top of the generated code, we add:

  • A client constructor that reads your credentials, region and host from the environment.
  • DocSpring.Sdk.NewClient(...) and DocSpring.Sdk.NewClientFromEnv(), which build a client without a .NET host builder.

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.

License

MIT. See LICENSE.

About

C# API Client for DocSpring

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages