好的,我对使用API&#39>的理解有限
我试图掌握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
答案 0 :(得分:4)
您误解了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<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; }
}
答案 1 :(得分:0)
链接到AdobeSign存储库:
ADOBE SIGN SDK C# SHARP API Ver. 6
Adobe Sign API集成商-这在AdobeSigns GIT存储库中是隐藏的。指向GIT项目中C#和REST客户端集成C#项目的所有已生成SWAGGER类(模型/方法)的链接,您可以在项目内部对其进行编译并将其用作项目参考或已编译的DLL。此项目已更新为使用API的版本6。对我来说,这节省了很多时间。我在下面提供了一个有关如何使用它的快速示例。我希望这也可以帮助其他人节省时间。
请注意,您可能必须在configuration.cs中关闭BasePath,以便在遇到404错误时可以检索初始的Adobe URI“ BaseURI”调用。
Change BasePath =“ http://localhost/api/rest/v6”;
收件人:
BasePath =“ https://api.echosign.com/api/rest/v6”;
//include namespaces:
using IO.Swagger.Api;
using IO.Swagger.model.agreements;
using IO.Swagger.model.baseUris;
using IO.Swagger.model.transientDocuments;
using System.IO;
然后,此快速的最小操作演示了BaseUri,又上传了临时文档,然后创建了协议(示例1基本签名者的最小选项)
string transientDocumentId = "";
string adobesignDocKey = "";
string baseURI = "";
var apiInstanceBase = new BaseUrisApi();
var authorization = "Bearer " + apiKey; //Example as Integration Key, see adobesign docs For OAuth.
try
{
//___________________GET BASEURI ADOBE SIGN_________________________
BaseUriInfo resultBase = apiInstanceBase.GetBaseUris(authorization);
baseURI = resultBase.ApiAccessPoint; //return base uri
//___________________UPLOAD YOUR PDF THEN REF ADOBE SIGN_________________________
var apiInstanceFileUpload = new TransientDocumentsApi(baseURI + "api/rest/v6/");
TransientDocumentResponse resultTransientID = apiInstanceFileUpload.CreateTransientDocument(authorization, File.OpenRead([ENTER YOUR LOCAL FILE PATH]), null, null, _filename, null);
if (!String.IsNullOrEmpty(resultTransientID.TransientDocumentId))
{
transientDocumentId = resultTransientID.TransientDocumentId; //returns the transient doc id to use below as reference
}
var apiInstance = new AgreementsApi(baseURI + "api/rest/v6/");
//___________________CREATE ADOBE SIGN_________________________
var agreementId = ""; // string | The agreement identifier, as returned by the agreement creation API or retrieved from the API to fetch agreements.
var agreementInfo = new AgreementCreationInfo();
//transientDocument, libraryDocument or a URL (note the full namespace/conflicts with System.IO
List<IO.Swagger.model.agreements.FileInfo> useFile = new List<IO.Swagger.model.agreements.FileInfo>();
useFile.Add(new IO.Swagger.model.agreements.FileInfo { TransientDocumentId = transientDocumentId });
agreementInfo.FileInfos = useFile;
//Add Email To Send To:
List<ParticipantSetMemberInfo> partSigners = new List<ParticipantSetMemberInfo>();
partSigners.Add( new ParticipantSetMemberInfo { Email = "[ENTER VALID EMAIL SIGNER]", SecurityOption=null });
//Add Signer To Participant
List<ParticipantSetInfo> partSetInfo = new List<ParticipantSetInfo>();
partSetInfo.Add(new ParticipantSetInfo { Name = "signer1", MemberInfos = partSigners, Role = ParticipantSetInfo.RoleEnum.SIGNER, Order=1, Label="" });
agreementInfo.ParticipantSetsInfo = partSetInfo;
agreementInfo.SignatureType = AgreementCreationInfo.SignatureTypeEnum.ESIGN;
agreementInfo.Name = "Example Esign For API";
agreementInfo.Message = "Some sample Message To Use Signing";
agreementInfo.State = AgreementCreationInfo.StateEnum.INPROCESS;
AgreementCreationResponse result = apiInstance.CreateAgreement(authorization, agreementInfo, null, null);
adobesignDocKey = result.Id; //returns the document Id to reference later to get status/info on GET
}
catch (Exception ex)
{
//Capture and write errors to debug or display to user
System.Diagnostics.Debug.Write(ex.Message.ToString());
}