Giter Club home page Giter Club logo

dotnet-anvil's Introduction

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:

pdf-template-id

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

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

dotnet-anvil's People

Contributors

aalmazan avatar benogle avatar manggit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.