Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adobe Sign (echo sign) API sending document using C#

Okay I have limited understanding of working with API's

Im trying to get to grips with Adobe Sign API and hit a dead end, on there test page i have enterd this and it works

enter image description here

But i have no idea on how then do that in C#

I have tried the following, but know its missing the OAuth stuff and I'm just not sure what to try next. by the way foo.GetAgreementCreationInfo() just gets the string that is in the screen shot, I just moved it out cus it was big and ugly

var foo = new Models();
var client = new RestClient("https://api.na1.echosign.com/api/rest/v5");
// client.Authenticator = new HttpBasicAuthenticator(username, password);
var request = new RestRequest("agreements/{AgreementCreationInfo}", Method.POST);
request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method
request.AddUrlSegment("AgreementCreationInfo",                     foo.GetAgreementCreationInfo()); // replaces matching token in request.Resource
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
like image 628
Ashley Kilgour Avatar asked Oct 15 '25 21:10

Ashley Kilgour


2 Answers

You are misinterpreting the API documentation. The Access-Token parameter needed in your API is clearly an HTTP header, while the AgreementCreationInfo is simply the request body in JSON format. There is no URI segment, so rewrite your code as follows:

var foo = new Models();
//populate foo
var client = new RestClient("https://api.na1.echosign.com/api/rest/v5");
var request = new RestRequest("agreements", Method.POST);
request.AddHeader("Access-Token", "access_token_here!");
// request.AddHeader("x-api-user", "userid:jondoe"); //if you want to add the second header
request.AddParameter("application/json", foo.GetAgreementCreationInfo(), ParameterType.RequestBody);

IRestResponse response = client.Execute(request);
var content = response.Content;

Please also be aware that in RESTSharp you do not need to manually serialize your body into JSON at all. If you create a strongly typed object (or just an anonymous object could be enough) that has the same structure of your final JSON, RESTSharp will serialize it for you.

For a better approach I strongly suggest you to replace this line:

request.AddParameter("application/json", foo.GetAgreementCreationInfo(), ParameterType.RequestBody);

With those:

request.RequestFormat = DataFormat.Json;
request.AddBody(foo);

Assuming your foo object is of type Models and has the following structure along with its properties:

public class Models
{
    public DocumentCreationInfo documentCreationInfo { get; set; }
}

public class DocumentCreationInfo
{
    public List<FileInfo> fileInfos { get; set; }
    public string name { get; set; }
    public List<RecipientSetInfo> recipientSetInfos { get; set; }
    public string signatureType { get; set; }
    public string signatureFlow { get; set; }
}

public class FileInfo
{
    public string transientDocumentId { get; set; }
}

public class RecipientSetInfo
{
    public List<RecipientSetMemberInfo> recipientSetMemberInfos { get; set; }
    public string recipientSetRole { get; set; }
}

public class RecipientSetMemberInfo
{
    public string email { get; set; }
    public string fax { get; set; }
}
like image 174
Federico Dipuma Avatar answered Oct 17 '25 13:10

Federico Dipuma


Link to AdobeSign Repository:

ADOBE SIGN SDK C# SHARP API Ver. 6

Adobe Sign API integrators - this is kind of hidden away in AdobeSigns GIT repositories. The link to all the generated SWAGGER classes (models/methods) for C# and REST client integrated C# project in a GIT project you can compile and use right inside your project as a project reference or compiled DLL. This project has been updated to use version 6 of the API. This was a huge time saver for me. I have provided a quick example below on how to use it. I hope this helps others save time as well.

Note you might have to switch out BasePath in the configuration.cs so you can retrieve the initial Adobe URI "BaseURI" call if you get 404 error.

Change BasePath = "http://localhost/api/rest/v6";

To:

BasePath = "https://api.echosign.com/api/rest/v6";

//include namespaces: 
using IO.Swagger.Api;
using IO.Swagger.model.agreements;
using IO.Swagger.model.baseUris;
using IO.Swagger.model.transientDocuments;
using System.IO;

Then this quick minimal demonstrates BaseUri, Upload PDF a.k.a. Transient Document, then Create Agreement (Example 1 Basic Signer Minimal Options)

        string transientDocumentId = "";
        string adobesignDocKey = "";
        string baseURI = "";
        var apiInstanceBase = new BaseUrisApi();
        var authorization = "Bearer " + apiKey;   //Example as Integration Key, see adobesign docs For OAuth.

        try
        {
            //___________________GET BASEURI ADOBE SIGN_________________________

            BaseUriInfo resultBase = apiInstanceBase.GetBaseUris(authorization);
            baseURI = resultBase.ApiAccessPoint; //return base uri

            //___________________UPLOAD YOUR PDF THEN REF ADOBE SIGN_________________________

            var apiInstanceFileUpload = new TransientDocumentsApi(baseURI + "api/rest/v6/");
            TransientDocumentResponse resultTransientID = apiInstanceFileUpload.CreateTransientDocument(authorization, File.OpenRead([ENTER YOUR LOCAL FILE PATH]), null, null, _filename, null);

            if (!String.IsNullOrEmpty(resultTransientID.TransientDocumentId))
            {
                transientDocumentId = resultTransientID.TransientDocumentId; //returns the transient doc id to use below as reference                    
            }

            var apiInstance = new AgreementsApi(baseURI + "api/rest/v6/");

            //___________________CREATE ADOBE SIGN_________________________

            var agreementId = "";  // string | The agreement identifier, as returned by the agreement creation API or retrieved from the API to fetch agreements.

            var agreementInfo = new AgreementCreationInfo();                

            //transientDocument, libraryDocument or a URL (note the full namespace/conflicts with System.IO
            List<IO.Swagger.model.agreements.FileInfo> useFile = new List<IO.Swagger.model.agreements.FileInfo>();
            useFile.Add(new IO.Swagger.model.agreements.FileInfo { TransientDocumentId = transientDocumentId });
            agreementInfo.FileInfos = useFile;

            //Add Email To Send To:
            List<ParticipantSetMemberInfo> partSigners = new List<ParticipantSetMemberInfo>();
            partSigners.Add( new ParticipantSetMemberInfo { Email = "[ENTER VALID EMAIL SIGNER]", SecurityOption=null });

            //Add Signer To Participant
            List<ParticipantSetInfo> partSetInfo = new List<ParticipantSetInfo>();
            partSetInfo.Add(new ParticipantSetInfo { Name = "signer1", MemberInfos = partSigners, Role = ParticipantSetInfo.RoleEnum.SIGNER, Order=1, Label="" });
            agreementInfo.ParticipantSetsInfo = partSetInfo;

            agreementInfo.SignatureType = AgreementCreationInfo.SignatureTypeEnum.ESIGN;
            agreementInfo.Name = "Example Esign For API";

            agreementInfo.Message = "Some sample Message To Use Signing";

            agreementInfo.State = AgreementCreationInfo.StateEnum.INPROCESS;

            AgreementCreationResponse result = apiInstance.CreateAgreement(authorization, agreementInfo, null, null);
            adobesignDocKey = result.Id; //returns the document Id to reference later to get status/info on GET                
        }
        catch (Exception ex) 
        {
            //Capture and write errors to debug or display to user 
            System.Diagnostics.Debug.Write(ex.Message.ToString());
        }
like image 26
moto_geek Avatar answered Oct 17 '25 13:10

moto_geek