的Adobe登录(回声号)API使用C#发送文件 [英] Adobe Sign (echo sign) API sending document using C#

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

问题描述

好吧,我已经用有限的API工作的认识。

我试着去与Adobe注册API夹具和进入了死胡同,但测试页上我已经照耀这和它的作品

在这里输入的形象描述

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

我曾尝试以下,但知道它缺少OAuth的东西,我只是不知道下一个尝试的东西。
顺便说一句foo.GetAgreementCreationInfo()刚刚获得那就是在屏幕截图的字符串,我刚搬到出来CUS这是大和丑陋

 无功富=新车型();
VAR的客户=新RESTClient实现(https://api.na1.echosign.com/api/rest/v5);
// client.Authenticator =新HttpBasicAuthenticator(用户名,密码);
VAR要求=新RestRequest(协议/ {} AgreementCreationInfo,Method.POST);
request.AddParameter(名,价值); //添加到信息或网址查询字符串根据方法
request.AddUrlSegment(AgreementCreationInfo,foo.GetAgreementCreationInfo()); //在request.Resource替换匹配令牌
IRestResponse响应= client.Execute(请求);
VAR内容= response.Content; //原始内容的字符串


解决方案

您是misinter preting API文档。你的API中所需的访问令牌参数显然是一个HTTP头,而 AgreementCreationInfo 简直就是请求主体中JSON格式。没有URI段,所以重写code如下:

 无功富=新车型();
//填充富
VAR的客户=新RESTClient实现(https://api.na1.echosign.com/api/rest/v5);
VAR要求=新RestRequest(协议,Method.POST);
request.AddHeader(访问令牌,access_token_here!);
// request.AddHeader(X-API的用户,用户ID:jondoe); //如果要添加第二个头部
request.AddParameter(应用/ JSON,foo.GetAgreementCreationInfo(),ParameterType.RequestBody);IRestResponse响应= client.Execute(请求);
VAR内容= response.Content;

另外请注意,在RESTSharp你不需要手动序列化你的身体成JSON的。如果您创建一个强类型的对象(或只是一个匿名的对象可以是足够的),有您的最终JSON的结构相同,RESTSharp将系列化给你。

对于一个更好的办法,我强烈建议您更换这行:

  request.AddParameter(应用/ JSON,foo.GetAgreementCreationInfo(),ParameterType.RequestBody);

使用这些:

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

假设你的对象的类型为模式并与及其属性的结构如下:

 公共类模型
{
    公共DocumentCreationInfo documentCreationInfo {搞定;组; }
}公共类DocumentCreationInfo
{
    公开名单<&的FileInfo GT; fileInfos {搞定;组; }
    公共字符串名称{;组; }
    公开名单< RecipientSetInfo> recipientSetInfos {搞定;组; }
    公共字符串signatureType {搞定;组; }
    公共字符串signatureFlow {搞定;组; }
}公共类的FileInfo
{
    公共字符串transientDocumentId {搞定;组; }
}公共类RecipientSetInfo
{
    公开名单< RecipientSetMemberInfo> recipientSetMemberInfos {搞定;组; }
    公共字符串recipientSetRole {搞定;组; }
}公共类RecipientSetMemberInfo
{
    公共字符串电子邮件{获得;组; }
    公共字符串传真{搞定;组; }
}

Okay I have limited understanding of working with API's

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

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

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

解决方案

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;

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

With those:

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

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登录(回声号)API使用C#发送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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