gpt4 book ai didi

c# - Adobe Sign(echo sign) API 发送文档使用C#

转载 作者:行者123 更新时间:2023-11-30 20:36:14 30 4
gpt4 key购买 nike

好吧,我对使用 API 的理解有限

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

enter image description here

但我不知道如何在 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 格式的请求正文。没有 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 中,您根本不需要手动将正文序列化为 JSON。如果您创建一个与最终 JSON 具有相同结构的强类型对象(或者只是一个匿名对象就足够了),RESTSharp 将为您序列化它。

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

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

与那些:

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

假设您的 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; }
}

关于c# - Adobe Sign(echo sign) API 发送文档使用C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37166341/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com