Adobe Sign(echo sign)API使用C#发送文档
好吧,我对使用API的理解有限
我试图掌握Adobe 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标头,而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 fileInfos { get; set; } public string name { get; set; } public List 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 recipientSetMemberInfos { get; set; } public string recipientSetRole { get; set; } } public class RecipientSetMemberInfo { public string email { get; set; } public string fax { get; set; } }