Anvil 0.5.0

dotnet add package Anvil --version 0.5.0
NuGet\Install-Package Anvil -Version 0.5.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Anvil" Version="0.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Anvil --version 0.5.0
#r "nuget: Anvil, 0.5.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Anvil as a Cake Addin
#addin nuget:?package=Anvil&version=0.5.0

// Install Anvil as a Cake Tool
#tool nuget:?package=Anvil&version=0.5.0

Horizontal Lockupblack Horizontal Lockup copywhite

dotnet-anvil

Nuget (with prereleases) GitHub

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.

  1. PDF filling API - fill out a PDF template with a web request and structured JSON data.
  2. PDF generation API - send markdown or HTML and Anvil will render it to a PDF.
  3. Etch e-sign with API - customizable, embeddable, e-signature platform with an API to control the signing process end-to-end.
  4. 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.

Installing

NuGet package page

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>

Usage

Create a client instance

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);

Example usage

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");
    }
}

API

RestClient.FillPdf

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:

<img width="725" alt="pdf-template-id" src="https://user-images.githubusercontent.com/69169/73693549-4a598280-468b-11ea-81a3-5df4472de8a4.png">

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);

RestClient.GeneratePdf

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");
    }
}

RestClient.DownloadDocuments

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");

GraphQLClient.CreateEtchPacket

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 = "morgan@example.com",
    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);

GraphQLClient.GetEtchPacket

Gets the details of an Etch Packet.

var client = new GraphQLClient(apiKey);
return await client.GetEtchPacket("etch-packet-eid-here");

GraphQLClient.GetEtchSignUrl

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;

GraphQLClient.SendQuery

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);
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
.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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.5.0 1,670 9/12/2022
0.4.0 386 9/7/2022
0.3.0 414 5/23/2022
0.2.0 426 3/4/2022
0.1.0-alpha3 138 1/25/2022
0.1.0-alpha2 144 1/20/2022
0.1.0-alpha1 152 1/20/2022
0.1.0-alpha 157 1/20/2022