Arex388.DocuSeal
2.1.0
dotnet add package Arex388.DocuSeal --version 2.1.0
NuGet\Install-Package Arex388.DocuSeal -Version 2.1.0
<PackageReference Include="Arex388.DocuSeal" Version="2.1.0" />
<PackageVersion Include="Arex388.DocuSeal" Version="2.1.0" />
<PackageReference Include="Arex388.DocuSeal" />
paket add Arex388.DocuSeal --version 2.1.0
#r "nuget: Arex388.DocuSeal, 2.1.0"
#:package Arex388.DocuSeal@2.1.0
#addin nuget:?package=Arex388.DocuSeal&version=2.1.0
#tool nuget:?package=Arex388.DocuSeal&version=2.1.0
Arex388.DocuSeal
Arex388.DocuSeal is a highly opinionated .NET Standard 2.0 library for the DocuSeal.co API. It is intended to be an easy, well structured, and highly performant client for interacting with the DocuSeal.co API for sending documents for e-signatures. It can be used in applications interacting with a single account using IDocuSealClient, or with applications interacting with multiple accounts using IDocuSealClientFactory.
As noted above, it is highly opinionated. The API documentation is not very clear, and there's redundancies, ambiguities, and object properties that I have no idea why they're there or what they stand for. While it has been one of the better documented APIs I've worked with, there was still some questionable design decisions about it. I've attempted to normalize the ambiguities, and to ignore the redundancies with this client.
Dependency Injection
To configure dependency injection use the AddDocuSeal() extensions on IServiceCollection. There are two signatures, with and without passing in a DocuSealClientOptions object. If the options object is passed to the extension, it will register IDocuSealClient for use with a single account, otherwise it will register IDocuSealClientFactory for use with multiple accounts.
Accounts on DocuSeal's EU region set Region = DocuSealRegion.Eu on the DocuSealClientOptions (it defaults to DocuSealRegion.Global), which sends requests to api.docuseal.eu instead of api.docuseal.com; the factory caches clients per authorization token and region.
How to Use
For a single account, inject the IDocuSealClient.
private readonly IDocuSealClient _docuSeal;
_ = await _docuseal.ListTemplatesAsync();
For multiple accounts, inject the IDocuSealClientFactory to create an instance per account.
private readonly IDocuSealClientFactory _docuSealFactory;
var docuseal = _docuSealFactory.CreateClient(new DocuSealClientOptions {
AuthorizationToken = "Your authorization token from DocuSeal.co"
});
_ = await docuseal.ListTemplatesAsync();
To download a submission's signed documents, pass the URL the API returned to DownloadDocumentAsync(). Content is not null exactly when Success is true, and it is only readable until the response is disposed.
var submission = await _docuSeal.GetSubmissionAsync(submissionId);
if (submission.Submission?.CombinedDocumentUrl is { } url) {
using var download = await _docuSeal.DownloadDocumentAsync(url);
if (download.Content is { } content) {
await content.CopyToAsync(destination);
}
}
The client provides methods for interacting with Templates, Submissions, and Submitters using the following methods:
Templates
ArchiveTemplateAsync()- Archive a template so it can't be used. This is essentially a soft delete.CloneTemplateAsync()- Clone a template.CreateTemplateAsync()- Create a new template.CreateTemplateFromHtmlAsync()- Create a new template from HTML with field tags.GetTemplateAsync()- Get an existing template.ListTemplatesAsync()- List all templates, with archived templates hidden by default.MergeTemplatesAsync()- Merge two or more templates into one.UpdateTemplateAsync()- Update a template.UpdateTemplateDocumentsAsync()- Update a template's documents.
Submissions
ArchiveSubmissionAsync()- Archive a submission so it can't be used. This is essentially a soft delete.CreateSubmissionAsync()- Create a new submission for a template. The response carries the new submission's id (SubmissionId) and oneSubmitterper submitter in the request (Submitters), each with theEmbedSrcof its signing form. It does not carry the submission itself, so callGetSubmissionAsync()with the id when you need it.CreateSubmissionFromDocxAsync()- Create a one-off submission from DOCX documents, without a saved template, filling[[variables]]fromVariables. The response carries the createdSubmission, with itsSubmittersand theEmbedSrcof each signing form; the API returns a subset of the submission, without documents, events, or template.CreateSubmissionFromEmailsAsync()- Create one submission per email address for a template, with the simplifiedPOST /submissions/emailsrequest. The response carries oneSubmitterper address (Submitters), each with its ownSubmissionIdand theEmbedSrcof its signing form.CreateSubmissionFromHtmlAsync()- Create a one-off submission from HTML documents with field tags, without a saved template. The response carries the createdSubmission, with itsSubmittersand theEmbedSrcof each signing form; the API returns a subset of the submission, without documents, events, or template.CreateSubmissionFromPdfAsync()- Create a one-off submission from PDF documents, without a saved template, with fields from{{text}}tags or from each document'sFields. The response carries the createdSubmission, with itsSubmittersand theEmbedSrcof each signing form; the API returns a subset of the submission, without documents, events, or template.DownloadDocumentAsync()- Download a document from a URL the API returned: a submission document'sUrl, a submission'sCombinedDocumentUrl, or itsAuditUrl. The response carries the content as aStream,ContentTypeandContentLength, and is disposable: dispose it when you are done reading. The download never sends your authorization token.GetSubmissionAsync()- Get an existing submission.GetSubmissionDocumentsAsync()- Get a submission's documents: the signed documents once it is completed, the partially filled ones before then. SetMustMergeon the request to merge them into a single PDF.ListSubmissionsAsync()- List submissions, optionally filtered by status, folder, template, or archived state. Archived submissions are not hidden unless you setIsArchivedtofalse.UpdateSubmissionAsync()- Update a submission's name or expiration, or archive or unarchive it. SetIsArchivedtofalseto unarchive it, andClearExpirationto remove its expiration (ExpireAtUtcandClearExpirationcannot be combined).
Submitters
GetSubmitterAsync()- Get a submitter for a submission.ListSubmittersAsync()- List the submitters for a submission.UpdateSubmitterAsync()- Update a submitter. The response carries the updated submitter, with itsEmbedSrc.
Webhooks
DocuSeal posts webhook events to an endpoint you host, so parsing them needs no client or authorization token. DocuSealWebhook.Parse() takes the request body, as a string or as UTF-8 bytes, and returns the event as the subtype matching its event_type:
FormWebhookEvent-form.viewed,form.started,form.completed, andform.declined.Datais the submitter, with itsSubmissionandTemplate.SubmissionWebhookEvent-submission.created,submission.completed, andsubmission.expired.Datais theSubmission.SubmissionArchivedWebhookEventandTemplateArchivedWebhookEvent-submission.archivedandtemplate.archived.Datacarries the archived object'sIdandArchivedAtUtc.TemplateWebhookEvent-template.createdandtemplate.updated.Datais theTemplate.UnknownWebhookEvent- anyevent_typethe client doesn't know yet, with the rawevent_typeinRawTypeand the unparseddatainData.
It never throws. It returns null when it can't read the payload, which doesn't by itself mean the request didn't come from DocuSeal:
- The body isn't valid JSON, including invalid UTF-16 or UTF-8 text.
- The body's root isn't an object.
event_typeis missing or isn't a string.timestampis missing or isn't an ISO 8601 date string.datais missing.- The
event_typeis known, but itsdataisn't an object or doesn't bind to its model.
app.MapPost("/webhooks/docuseal", async (HttpRequest request) => {
using var reader = new StreamReader(request.Body);
var webhookEvent = DocuSealWebhook.Parse(await reader.ReadToEndAsync());
switch (webhookEvent) {
case FormWebhookEvent { Type: WebhookEventType.FormCompleted } formCompleted:
// formCompleted.Data.Email, formCompleted.Data.Values, ...
break;
case SubmissionWebhookEvent { Type: WebhookEventType.SubmissionCompleted } submissionCompleted:
// submissionCompleted.Data.Documents, ...
break;
case null:
return Results.BadRequest();
}
return Results.Ok();
});
Parse() only reads the body; it doesn't authenticate the request, so check that it came from DocuSeal before acting on it.
Hoping for API Improvements
For the most part the API is one of the most well structured ones I've built a client for, and the OpenAPI spec has since settled most of what used to bother me. Creating a submission returns the submitters of the one submission that was created, not a submission that sometimes comes back as an array: in each of them id is the submitter's id and submission_id is the submission's id, which is why CreateSubmission.Response exposes SubmissionId and Submitters and Submission.Id is simply the id of the submission body. The status values, and every other enum, are defined, so the client types them (SubmissionStatus, SubmitterStatus, and the rest). It still has a couple of flaws:
- You can't ever delete something in DocuSeal, you can only archive it, which is just a soft delete. I would have preferred it if deleting was actually deleting, and archiving was just a specific update. The API can at least unarchive now: updating a submission (
UpdateSubmissionAsync()) or a template (UpdateTemplateAsync()) withIsArchivedset tofalseunarchives it. - Responses have properties that just don't seem to be relevant to anything. I've kept the majority, simply because I wasn't sure if users of this library might find them useful or not.
I'm sure there's something I've missed, but that's all I can remember now that I am at the end of two weeks of building this client. Hopefully, the DocuSeal API will improve in the future to address these, in my opinion, flaws.
That being said, it's a night-and-day difference working with the DocuSeal API vs the DocuSign API. The DocuSign API is absolutely the most awful API I've ever worked with.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- FluentValidation (>= 11.12.0 && < 12.0.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.12.0 && < 12.0.0)
- Microsoft.Extensions.Caching.Memory (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Http (>= 10.0.12)
- System.Net.Http.Json (>= 10.0.12)
- System.Text.Json (>= 10.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.