Skip to main content

Get Documents Signed Using Adobe Sign API in C#





Electronic signatures have revolutionized the way businesses handle document workflows. Instead of dealing with cumbersome paper-based processes, electronic signatures offer a streamlined and efficient way to obtain legally binding signatures. Adobe Sign API takes this concept to the next level by providing developers with the tools to seamlessly integrate electronic signature capabilities into their applications. In this blog post, we will explore how to use the Adobe Sign API to send documents for signature via email using C#

 

Understanding Electronic Signatures and Adobe Sign API

Electronic signatures, also known as e-signatures, are digital representations of a person's intent to agree to the content of a document. They hold the same legal weight as traditional ink signatures but offer the advantage of speed and convenience. Adobe Sign API allows developers to programmatically incorporate e-signatures into their applications, automating the signature process and enhancing the user experience.

 

Setting Up Your Development Environment

Before we dive into the code, let's make sure you have the necessary setup:

Adobe Sign Developer Account: If you don't have an Adobe Sign developer account, sign up for one at Adobe Sign Developer Portal.

Client ID and Client Secret: After creating an Adobe Sign developer account, obtain your Client ID and Client Secret from the Adobe Sign Console.

C# Development Environment: Ensure you have a C# development environment set up, which includes Visual Studio or any preferred code editor.

Authenticating with the Adobe Sign API

To begin, we need to authenticate with the Adobe Sign API to obtain an access token. This token will be used to authorize our API requests.

using System;

using System.Net.Http;

using System.Net.Http.Headers;

using System.Text;

using System.Threading.Tasks;

 

class Program

{

    static async Task Main(string[] args)

    {

        // Replace with your actual Adobe Sign API credentials

        string clientId = "YOUR_CLIENT_ID";

        string clientSecret = "YOUR_CLIENT_SECRET";

        string accessToken = await GetAccessToken(clientId, clientSecret);

 

        if (!string.IsNullOrEmpty(accessToken))

        {

            // Continue with sending documents for signature

        }

        else

        {

            Console.WriteLine("Authentication failed.");

        }

    }

 

    static async Task<string> GetAccessToken(string clientId, string clientSecret)

    {

        using (HttpClient client = new HttpClient())

        {

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

 

            string url = "https://api.echosign.com/oauth/token";

            string requestBody = $"grant_type=client_credentials&client_id={clientId}&client_secret={clientSecret}";

            var response = await client.PostAsync(url, new StringContent(requestBody, Encoding.UTF8, "application/x-www-form-urlencoded"));

 

            if (response.IsSuccessStatusCode)

            {

                var tokenResponse = await response.Content.ReadAsStringAsync();

                // Parse tokenResponse and return access token

                // ...

            }

            return null;

        }

    }

}

 

Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your actual Adobe Sign API credentials.

Sending Documents for Signature

With the access token obtained, we can now use the Adobe Sign API to send documents for signature. Here's a simplified example of how you might do this:

static async Task<string> SendDocumentForSignature(string accessToken)

{

    using (HttpClient client = new HttpClient())

    {

        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

 

        string url = "https://api.echosign.com/api/rest/v6/agreements";

        string requestBody = "{\"documentCreationInfo\": {\"fileInfos\": [{\"libraryDocumentId\": \"YOUR_LIBRARY_DOCUMENT_ID\"}],\"name\": \"Sample Agreement\",\"recipientSetInfos\": [{\"recipientSetMemberInfos\": [{\"email\": \"recipient@example.com\",\"role\": \"SIGNER\"}],\"recipientSetRole\": \"SIGNER\"}],\"signatureType\": \"ESIGN\",\"state\": \"IN_PROCESS\"}}";

 

        var response = await client.PostAsync(url, new StringContent(requestBody, Encoding.UTF8, "application/json"));

 

        if (response.IsSuccessStatusCode)

        {

            var agreementResponse = await response.Content.ReadAsStringAsync();

            // Parse agreementResponse and return agreement ID

            // ...

        }

        return null;

    }

}

 

 

 

Replace YOUR_LIBRARY_DOCUMENT_ID with the actual library document ID you want to send for signature.

 

Conclusion

Integrating electronic signatures into your application using the Adobe Sign API opens up new possibilities for automating document workflows. In this blog post, we explored the basics of authenticating with the API and sending documents for signature via email using C#. Remember that this is just a starting point, and there's much more you can achieve with the Adobe Sign API, such as managing signature workflows, handling callbacks, and implementing error handling strategies.

 

Popular posts from this blog

Test Azure AD secured API with Postman

API deployed on Azure and secured by Azure AD. For example, we will create a simple Azure Function that returns weather data.  public static async Task Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); try { HttpResponseMessage response; AuthenticationContext authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/xxxxxxxxx"); ClientCredential clientCredential = new ClientCredential("xxxxx-xxxxx", "xxxxxx"); AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync("xxxx-xxxxx-xxxxx", clientCredential).Result; using (var httpClient = new HttpClient()) ...

Working with RabbitMQ using C#

RabbitMQ Topology A Queue  that works on the basis of FIFO (first in first out).  A Publisher is the component that generates some data that is pushed to the queue.  Installation Install the correct version of Erlang based on the operating system you are using. Download and install RabbitMQ server . Now  install the RabbitMQ .Net client from NuGet Package Manager. Sample Codes using RabbitMQ.Client; using RabbitMQ.Client.Events; using System; using System.Text; using System.Threading; namespace PracticeRabbitMQ {     class Program     {         static void Main()         {             SendMessage("MessageID", "{MessageID: 1, MessageBody: 'Sample Message' }");             ReceiveMessage("MessageID");             Console.ReadLine();         }   ...