Adobe Sign(回声符号)API 使用 C# 发送文档

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

好吧,我对API

的工作理解有限

我试图掌握 Adob​​e Sign API 并遇到了死胡同,在测试页面上我输入了这个并且它有效

但我不知道如何在 C# 中做到这一点

我尝试了以下方法,但我知道它缺少 OAuth 内容,我只是不确定下一步该尝试什么。 顺便说一下 foo.GetAgreementCreationInfo() 只是获取屏幕截图中的字符串,我只是将它移出因为它又大又丑

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

您误解了 API 文档。 API 中所需的 Access-Token 参数显然是 HTTP header,而 AgreementCreationInfo 只是 JSON 格式的请求 body。没有URI段,所以重写你的代码如下:

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;

另请注意,在 RESTSharp 中,您根本不需要手动将 body 序列化为 JSON。如果您创建一个强类型 object(或者只是一个匿名 object 就足够了),它具有与最终 JSON 相同的结构,RESTSharp 将为您序列化它。

为了更好的方法,我强烈建议您替换这一行:

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

与那些:

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

假设您的 foo object 是 Models 类型并且具有以下结构及其属性:

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

Link 至 Adob​​eSign 存储库:

ADOBE SIGN SDK C# SHARP API Ver. 6

Adobe Sign API 集成商 - 这有点隐藏在 Adob​​eSigns GIT 存储库中。 link 所有生成的 SWAGGER 类 (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项目参考或编译的 DLL。此项目已更新为使用 API 的版本 6。这对我来说节省了大量时间。我在下面提供了一个关于如何使用它的快速示例。我希望这也能帮助其他人节省时间。

请注意,您可能必须在 configuration.cs 中关闭 BasePath,以便在出现 404 错误时可以检索初始 Adob​​e URI "BaseURI" 调用。

更改 BasePath = "http://localhost/api/rest/v6";

收件人:

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;

然后这个快速的最小演示 BaseUri,上传 PDF a.k.a。临时文档,然后创建协议(示例 1 基本签名者最小选项

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