Docusignapi 如何动态设置模板角色签名者“;电邮;及;名称“;使用RESTV2 API创建模板

Docusignapi 如何动态设置模板角色签名者“;电邮;及;名称“;使用RESTV2 API创建模板,docusignapi,Docusignapi,我感兴趣的是从模板中获取角色签名者,并为模板签名请求分配角色签名者电子邮件和签名者名称。使用REST v2 API是否可以做到这一点?是的,使用签名者的电子邮件和姓名将签名者分配给模板角色绝对是可能且容易的。您在开发者中心看过DocuSignAPI演练吗?它们包含用6种不同语言为9种常见API场景编写的示例代码,从其中一个模板发送。您可以在此处通过API工具页面找到演练: 例如,下面是代码的完整C#版本。只需替换顶部变量的值并运行!(注意,您还必须在开发人员帐户中创建模板,并将template

我感兴趣的是从模板中获取角色签名者,并为模板签名请求分配角色签名者电子邮件和签名者名称。使用REST v2 API是否可以做到这一点?

是的,使用签名者的电子邮件和姓名将签名者分配给模板角色绝对是可能且容易的。您在开发者中心看过DocuSignAPI演练吗?它们包含用6种不同语言为9种常见API场景编写的示例代码,从其中一个模板发送。您可以在此处通过API工具页面找到演练:

例如,下面是代码的完整C#版本。只需替换顶部变量的值并运行!(注意,您还必须在开发人员帐户中创建模板,并将
templateId
复制到代码中):

//C中的DocuSign API演练01#-从模板请求签名
//
//要运行此示例,请执行以下操作:
//1)创建一个新的.NET项目。
//2)向项目添加4个程序集引用:System、System.Net、System.XML和System.XML.Linq
//3)更新代码中的电子邮件、密码、集成商密钥和模板变量
//4)编译并运行
//
//注意1:此示例要求您首先通过DocuSign成员控制台创建模板。
//
//注2:docusignrestapi同时接受JSON和XML格式的http请求。这些C#API演练
//演示XML格式的使用,而其他演练显示JSON格式的示例。
使用制度;
使用System.IO;
Net系统;
使用System.Xml;
使用System.Xml.Linq;
命名空间DocuSignAPIWalkthrough01
{
公共类RequestSignatureFromTemplate
{
公共静态void Main()
{
//---------------------------------------------------------------------------------------------------
//输入以下7个变量的值:
//---------------------------------------------------------------------------------------------------
字符串username=“***”;//您的帐户电子邮件
string password=“***”;//您的帐户密码
string integratorKey=“***”;//您的帐户Integrator密钥(在首选项->API页面上找到)
string templateId=“***”;//帐户中模板的有效templateId
string templateRole=“***”;//存在于上述模板上的模板角色
字符串recipientName=“***”;//收件人(签名者)名称
字符串recipientEmail=“***”;//收件人(签名者)电子邮件
//---------------------------------------------------------------------------------------------------
//附加变量声明
string baseURL=“;//我们将通过登录API调用检索此内容
试一试{
//============================================================================
//步骤1-登录API调用(用于检索baseUrl)
//============================================================================
//登录api调用的端点(在演示环境中):
字符串url=”https://demo.docusign.net/restapi/v2/login_information";
//设置请求url、方法和标题。登录api调用不需要正文
HttpWebRequest请求=initializeRequest(url,“GET”,null,用户名,密码,integratorKey);
//读取http响应
字符串响应=GetResponseBy(请求);
//从响应体解析baseUrl值
baseURL=parseDataFromResponse(响应,“baseURL”);
//---显示结果
Console.WriteLine(“\nAPI调用结果:\n\n”+prettyPrintXml(响应));
//============================================================================
//步骤2-从模板发送签名请求
//============================================================================
//将“/信封”附加到baseURL并用于签名请求api调用
url=baseURL+“/信封”;
//构造一个输出XML格式的请求体(也接受JSON)
字符串requestBody=
"" +
“已发送”+
“DocuSign API-来自模板的签名请求”+
“”+templateId+“”+
"" + 
"" + 
“”+recipientName+“”+
“”+收件人电子邮件+“”+
“”+templateRole+“”+
"" + 
"" + 
"";
//设置请求url、方法、正文和标题
请求=initializeRequest(url,“POST”、请求主体、用户名、密码、integratorKey);
//读取http响应
response=getResponseBody(请求);
//---显示结果
Console.WriteLine(“\nAPI调用结果:\n\n”+prettyPrintXml(响应));
}
捕获(WebE例外){
使用(WebResponse=e.response){
HttpWebResponse httpResponse=(HttpWebResponse)响应;
WriteLine(“错误代码:{0}”,httpResponse.StatusCode);
使用(Stream data=response.GetResponseStream())
{
字符串文本=新的StreamReader(数据).ReadToEnd();
WriteLine(prettyPrintXml(text));
}
}
}
}//结束main()
//***
// DocuSign API Walkthrough 01 in C# - Request Signature from Template
//
// To run this sample: 
//  1) Create a new .NET project.
//  2) Add 4 assembly references to the project:  System, System.Net, System.XML, and System.XML.Linq
//  3) Update the email, password, integrator key, and template variables in the code
//  4) Compile and Run
//
// NOTE 1: This sample requires that you first create a Template through the DocuSign member Console.
//
// NOTE 2: The DocuSign REST API accepts both JSON and XML formatted http requests.  These C# API walkthroughs
//     demonstrate the use of XML format, whereas the other walkthroughs show examples in JSON format.
using System; 
using System.IO; 
using System.Net;
using System.Xml;
using System.Xml.Linq;

namespace DocuSignAPIWalkthrough01 
{
    public class RequestSignatureFromTemplate 
    {
        public static void Main ()
        {
            //---------------------------------------------------------------------------------------------------
            // ENTER VALUES FOR THE FOLLOWING 7 VARIABLES:
            //---------------------------------------------------------------------------------------------------
            string username = "***";        // your account email
            string password = "***";        // your account password
            string integratorKey = "***";       // your account Integrator Key (found on Preferences -> API page)
            string templateId = "***";      // valid templateId from a template in your account
            string templateRole = "***";        // template role that exists on above template
            string recipientName = "***";       // recipient (signer) name
            string recipientEmail = "***";      // recipient (signer) email
            //---------------------------------------------------------------------------------------------------

            // additional variable declarations
            string baseURL = "";            // we will retrieve this through the Login API call

            try {
                //============================================================================
                //  STEP 1 - Login API Call (used to retrieve your baseUrl)
                //============================================================================

                // Endpoint for Login api call (in demo environment):
                string url = "https://demo.docusign.net/restapi/v2/login_information";

                // set request url, method, and headers.  No body needed for login api call
                HttpWebRequest request = initializeRequest( url, "GET", null, username, password, integratorKey);

                // read the http response
                string response = getResponseBody(request);

                // parse baseUrl value from response body
                baseURL = parseDataFromResponse(response, "baseUrl");

                //--- display results
                Console.WriteLine("\nAPI Call Result: \n\n" + prettyPrintXml(response));

                //============================================================================
                //  STEP 2 - Send Signature Request from Template
                //============================================================================

                // append "/envelopes" to baseURL and use for signature request api call
                url = baseURL + "/envelopes";

                // construct an outgoing XML formatted request body (JSON also accepted)
                string requestBody = 
                    "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
                        "<status>sent</status>" + 
                        "<emailSubject>DocuSign API - Signature Request from Template</emailSubject>" +
                        "<templateId>" + templateId + "</templateId>" + 
                        "<templateRoles>" + 
                            "<templateRole>" + 
                                "<name>" + recipientName + "</name>" +
                                "<email>" + recipientEmail + "</email>" +   
                                "<roleName>" + templateRole + "</roleName>" + 
                            "</templateRole>" + 
                        "</templateRoles>" + 
                    "</envelopeDefinition>";

                // set request url, method, body, and headers
                request = initializeRequest( url, "POST", requestBody, username, password, integratorKey);

                // read the http response
                response = getResponseBody(request);

                //--- display results
                Console.WriteLine("\nAPI Call Result: \n\n" + prettyPrintXml(response));
            }
            catch (WebException e) {
                using (WebResponse response = e.Response) {
                    HttpWebResponse httpResponse = (HttpWebResponse)response;
                    Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
                    using (Stream data = response.GetResponseStream())
                    {
                        string text = new StreamReader(data).ReadToEnd();
                        Console.WriteLine(prettyPrintXml(text));
                    }
                }
            }
        } // end main()

        //***********************************************************************************************
        // --- HELPER FUNCTIONS ---
        //***********************************************************************************************
        public static HttpWebRequest initializeRequest(string url, string method, string body, string email, string password, string intKey)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url);
            request.Method = method;
            addRequestHeaders( request, email, password, intKey );
            if( body != null )
                addRequestBody(request, body);
            return request;
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static void addRequestHeaders(HttpWebRequest request, string email, string password, string intKey)
        {
            // authentication header can be in JSON or XML format.  XML used for this walkthrough:
            string authenticateStr = 
                "<DocuSignCredentials>" + 
                    "<Username>" + email + "</Username>" +
                    "<Password>" + password + "</Password>" + 
                    "<IntegratorKey>" + intKey + "</IntegratorKey>" +
                    "</DocuSignCredentials>";
            request.Headers.Add ("X-DocuSign-Authentication", authenticateStr);
            request.Accept = "application/xml";
            request.ContentType = "application/xml";
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static void addRequestBody(HttpWebRequest request, string requestBody)
        {
            // create byte array out of request body and add to the request object
            byte[] body = System.Text.Encoding.UTF8.GetBytes (requestBody);
            Stream dataStream = request.GetRequestStream ();
            dataStream.Write (body, 0, requestBody.Length);
            dataStream.Close ();
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static string getResponseBody(HttpWebRequest request)
        {
            // read the response stream into a local string
            HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse ();
            StreamReader sr = new StreamReader(webResponse.GetResponseStream());
            string responseText = sr.ReadToEnd();
            return responseText;
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static string parseDataFromResponse(string response, string searchToken)
        {
            // look for "searchToken" in the response body and parse its value
            using (XmlReader reader = XmlReader.Create(new StringReader(response))) {
                while (reader.Read()) {
                    if((reader.NodeType == XmlNodeType.Element) && (reader.Name == searchToken))
                        return reader.ReadString();
                }
            }
            return null;
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static string prettyPrintXml(string xml)
        {
            // print nicely formatted xml
            try {
                XDocument doc = XDocument.Parse(xml);
                return doc.ToString();
            }
            catch (Exception) {
                return xml;
            }
        }
    } // end class
} // end namespace