Adobe Sign(回声签名)API 使用 C# 发送文档 [英] Adobe Sign (echo sign) API sending document using C#

查看:33
本文介绍了Adobe Sign(回声签名)API 使用 C# 发送文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Okay I have limited understanding of working with API's

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

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

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

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

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

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

推荐答案

您误解了 API 文档.API 中所需的 Access-Token 参数显然是一个 HTTP 标头,而 AgreementCreationInfo 只是 JSON 格式的请求正文.没有 URI 段,因此按如下方式重写您的代码:

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;

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

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

那些:

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

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

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

这篇关于Adobe Sign(回声签名)API 使用 C# 发送文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆