Adobe Sign(回声签名)API 使用 C# 发送文档

Ash*_*our 3 c# api restsharp asp.net-web-api echosign

好吧,我对使用 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
Run Code Online (Sandbox Code Playgroud)

Fed*_*uma 5

您误解了 API 文档。Access-Token您的 API 中所需的参数显然是一个 HTTP 标头,而AgreementCreationInfo只是 JSON 格式的请求正文。没有 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;
Run Code Online (Sandbox Code Playgroud)

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

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

request.AddParameter("application/json", foo.GetAgreementCreationInfo(), ParameterType.RequestBody);
Run Code Online (Sandbox Code Playgroud)

和那些:

request.RequestFormat = DataFormat.Json;
request.AddBody(foo);
Run Code Online (Sandbox Code Playgroud)

假设您的foo对象属于类型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; }
}
Run Code Online (Sandbox Code Playgroud)