This is a library that provides an interface to access the Anvil API from applications written in .NET languages: C# etc.
Anvil provides easy APIs for all things paperwork.
- PDF filling API - fill out a PDF template with a web request and structured JSON data.
- PDF generation API - send markdown or HTML and Anvil will render it to a PDF.
- Etch e-sign with API - customizable, embeddable, e-signature platform with an API to control the signing process end-to-end.
- Anvil Workflows (w/ API) - Webforms PDF e-sign with a powerful no-code builder. Easily collect structured data, generate PDFs, and request signatures.
Learn more on our Anvil developer page. See the API guide and the GraphQL reference for full documentation.
Using the dotnet
CLI:
$ dotnet add package Anvil --version 0.5.0
Add as a package reference:
<ItemGroup>
<PackageReference Include="Anvil" Version="0.5.0" />
</ItemGroup>
using Anvil.Client;
var apiKey = "API-KEY-FROM-SETTINGS";
// For GraphQL-related queries
var client = new GraphQLClient(apiKey);
// If you are looking to use the PDF fill or PDF generate endpoints
// use the REST Client.
var restClient = new RestClient(apiKey);
Also see the example in the examples/
directory.
using Anvil.Client;
using Anvil.Payloads.Request.Types;
using Anvil.Payloads.Response;
class Program
{
const string apiKey = "MY-API-KEY";
static async Task<bool> GeneratePdfExampleData()
{
var restClient = new RestClient(apiKey);
var payload = new Anvil.Payloads.Request.GeneratePdf
{
Title = "My Document Title",
Type = "markdown",
Data = new List<IGeneratePdfListable>
{
new GeneratePdfItem
{
Label = "new thing1",
Content = "Content1",
FontSize = "20",
TextColor = "#CC0000"
},
new GeneratePdfItem
{
Label = "new thing2",
Content = "Content2"
},
}
};
return await restClient.GeneratePdf(payload, "/path/for/file/what.pdf");
}
}
- RestClient.FillPdf
- RestClient.GeneratePdf
- RestClient.DownloadDocuments
- GraphQLClient.CreateEtchPacket
- GraphQLClient.GetEtchPacket
- GraphQLClient.GetEtchSignUrl
- GraphQLClient.DownloadDocuments
- GraphQLClient.SendQuery
Fills a PDF template with your JSON data.
First, you will need to have uploaded a PDF to Anvil. You can find the PDF template's id on the API Info
tab of your PDF template's page:
An example:
var restClient = new RestClient(apiKey);
// Use Payload.Request objects to create your API call.
var payload = new Anvil.Payloads.Request.FillPdf
{
Title = "My PDF Title",
TextColor = "#CC0000",
Data = new Dictionary<string, object>
{
{ "simpleTextField", "string data" },
// Some fields are JSON objects, use an object initializer for those.
// In your PDF template's API info page, you can see if your field has
// additional data.
{ "phone", new {
Num = "5551231234",
Region = "US"
} },
}
};
// This will return a `Stream`
await restClient.FillPdf("your-template-eid", payload);
// This will write directly to the path you specify
await restClient.FillPdf("your-template-eid", payload, "/tmp/file.pdf");
// A version number can also be passed in. This will retrieve a specific
// version of the PDF to be filled if you don't want the current version
// to be used.
// You can also use the constant `ClientConstants.VERSION_LATEST` to fill a PDF
// that has not been published yet. Use this if you'd like to fill out a draft
// version of your template/PDF.
await restClient.FillPdf("your-template-eid", payload, ClientConstants.VERSION_LATEST);
// or specify a version number
await restClient.FillPdf("your-template-eid", payload, 5);
// specify a version number with an output file path
await restClient.FillPdf("your-template-eid", payload, "/tmp/file.pdf", 5);
Dynamically generate a new PDF from your HTML and CSS or markdown.
using Anvil.Client;
using Anvil.Payloads.Request.Types;
using Anvil.Payloads.Response;
class Program
{
const string apiKey = "MY-API-KEY";
static async Task<bool> GeneratePdfExampleData()
{
var restClient = new RestClient(apiKey);
var payload = new Anvil.Payloads.Request.GeneratePdf
{
Title = "My Document Title",
Type = "markdown",
Data = new List<IGeneratePdfListable>
{
new GeneratePdfItem
{
Label = "new thing1",
Content = "Content1",
FontSize = "20",
TextColor = "#CC0000"
},
new GeneratePdfItem
{
Label = "new thing2",
Content = "Content2"
},
}
};
return await restClient.GeneratePdf(payload, "/path/for/file/what.pdf");
}
}
Returns a Stream
of the document group specified by the documentGroupEid in Zip file format.
var restClient = new RestClient(apiKey);
return await restClient.DownloadDocuments("document-group-eid-here");
Creates an Etch Packet and optionally sends it to the first signer.
var client = new GraphQLClient(apiKey);
// This is from your "Document Templates" area in your Anvil account.
var templateId = "template-id-from-anvil";
// Add one or more files to a List for the upcoming payload.
// The "files" here are existing Casts in your Anvil account.
var files = new List<IEtchPacketAttachable>
{
new EtchCastRef
{
// Remember this `Id`. You will assign it to the signer below.
Id = "existingCastReference",
CastEid = templateId,
}
};
// Create your signer and also assign it to a signature field
// from the above template (the `Fields` property).
var signer = new EtchSigner
{
Id = "custom-signer-id",
Name = "Morgan Johnson",
Email = "[email protected]",
Fields = new[]
{
new SignerField
{
FieldId = "sign1",
FileId = "existingCastReference",
}
}
};
var signers = new List<EtchSigner> { signer };
// Put it all together.
var payload = new Anvil.Payloads.Request.CreateEtchPacket
{
Name = "Etch packet name",
IsDraft = false,
IsTest = true,
SignatureEmailBody = "Please sign this!",
SignatureEmailSubject = "Your signature is required",
Signers = signers.ToArray(),
Files = files.ToArray(),
// If you'd like all your PDFs merged into one when signing, and in the resulting zip package.
// Defaults to `false`.
// MergePdfs = true,
};
var response = await client.CreateEtchPacket(payload);
Gets the details of an Etch Packet.
var client = new GraphQLClient(apiKey);
return await client.GetEtchPacket("etch-packet-eid-here");
Generates an Etch sign URL for an Etch Packet signer. The Etch Packet and its signers must have already been created.
var client = new GraphQLClient(apiKey);
var signerEid = "some-id-here-from-etch-packet";
var clientUserId = "your-systems-signer-id";
var data = await client.GenerateEtchSignUrl(signerEid, clientUserId);
// The URL for signing is here
var url = data.GenerateEtchSignUrl;
A fallback function for queries and mutations without a specialized function in this client.
See the GraphQL reference for a listing on all possible queries.
var client = new GraphQLClient(apiKey);
var query = @"
query currentUser { currentUser { id } }
";
// `response` will be a `JObject` type and you can get different
// object fields by using the indexer operator (`[]`). Note that
// the field names are in the same case as in the query (camelCase)
// and won't follow the typical C# PascalCase as in the defined
// types in this library.
var response = await client.SendQuery(query, null);