我正在创建一个嵌入式解决方案。在我的应用程序的某个时刻,用户可以上传文件。我的模板中有一个必需的附件字段。如果用户在我的应用程序中上传了一个文件,我想在信封创建期间附加它,否则我希望docusign签名视图强制附件。在任何一种情况下,我希望它看起来与接收最终签名文档的用户相同(即:作为单独的附件)。我正在寻找如何实现这一目标的XML示例。这篇文章有一个类似于我想要做的推荐解决方案,但是没有代码:Attachments on iPad in iFrame docusign,这篇文章提到了一个可能是我想要的例子,但链接被破坏了:{{3 }}
或者如果有人能指出我当前的位置:
What is expected for the EnvelopeAttachment parameters of "Type" and "Label"?
我正在寻找的非工作示例:
public void AddAttachment2Envelope(string envelopeID, byte[] attachment, string attachmentname)
{
string url = baseURL + "/envelopes/" + envelopeID + "/documents";
string requestBody =
"--AAA" + "\r\n" +
"Content-Type: application/xml" + "\r\n" +
"Content-Disposition: form-data" + "\r\n" +
"<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" + "\r\n" +
"<documents>" + "\r\n" +
"<document>" + "\r\n" +
"<documentId>12345</documentId>" + "\r\n" + //what is documentid here used for?
"<name>" + attachmentname + "</name>" + "\r\n" +
"<order>1</order>" + "\r\n" +
"</document>" + "\r\n" +
"</documents>" + "\r\n" +
"</envelopeDefinition>" + "\r\n" +
"--AAA" + "\r\n" +
"Content-Type: application/pdf" + "\r\n" +
"Content-Disposition: file; filename=\"String content\"; documentId=10" + "\r\n" + //what is documentid here used for?
attachment.ToString() + "\r\n" +
"--AAA";
HttpWebRequest request = initializeRequest(url, "PUT", requestBody, email, password);
request.ContentType = "multipart/form-data; boundary=AAA";
string response = getResponseBody(request);
}
我也尝试了以下但没有成功:
public void AddAttachment2Envelope(string envelopeID, byte[] attachment, string attachmentname, Boolean bad)
{
string ctype = "Content-Type: application/pdf";
if (attachmentname.ToLower().EndsWith(".jpg"))
ctype = "Content-Type: image/jpeg";
else if (attachmentname.ToLower().EndsWith(".png"))
ctype = "Content-Type: image/png";
string url = baseURL + "/envelopes/" + envelopeID + "/documents/10";
string requestBody =
ctype + "\r\n" +
"Content-Disposition: file; filename=\"" + attachmentname + "\"; documentId=10" + "\r\n" +
System.Text.Encoding.Default.GetString(attachment) + "\r\n" + //System.Text.Encoding.Default.GetString(attachment) //System.Convert.ToBase64String(attachment, 0, attachment.Length)
"";
HttpWebRequest request = initializeRequest(url, "PUT", requestBody, email, password);
request.ContentType = ctype.Replace("Content-Type: ", "");
request.Headers.Add("Content-Disposition", "file; filename=\"" + attachmentname + "\"; documentId=10");
string response = getResponseBody(request);
}
public void AddAttachment2Envelope(string envelopeID, byte[] attachment, string attachmentname)
{
string ctype = "Content-Type: application/pdf";
if (attachmentname.ToLower().EndsWith(".jpg"))
ctype = "Content-Type: image/jpeg";
else if (attachmentname.ToLower().EndsWith(".png"))
ctype = "Content-Type: image/png";
string url = baseURL + "/envelopes/" + envelopeID + "/documents";
string requestBody =
"--AAA" + "\r\n" +
"Content-Type: application/xml" + "\r\n" +
"Content-Disposition: form-data" + "\r\n" +
//"<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" + "\r\n" +
//"<documents>" + "\r\n" +
"<document>" + "\r\n" +
"<documentId>10</documentId>" + "\r\n" +
"<name>" + attachmentname + "</name>" + "\r\n" +
"<order>2</order>" + "\r\n" +
//"<FileExtension>" + System.IO.Path.GetExtension(attachmentname).Replace(".", "").ToLower() + "</FileExtension>" + "\r\n" +
"</document>" + "\r\n" +
//"</documents>" + "\r\n" +
//"</envelopeDefinition>" + "\r\n" +
"--AAA" + "\r\n" +
ctype + "\r\n" +
"Content-Disposition: file; filename=\"" + attachmentname + "\"; documentId=10" + "\r\n" +
System.Convert.ToBase64String(attachment, 0, attachment.Length) + "\r\n" + //System.Text.Encoding.Default.GetString(attachment)
"--AAA--";
HttpWebRequest request = initializeRequest(url, "PUT", requestBody, email, password);
request.ContentType = "multipart/form-data; boundary=AAA";
//request.Accept = "multipart/form-data;";
string response = getResponseBody(request);
}
public void AddAttachment2Envelope(string envelopeID, byte[] attachment, string attachmentname, int bad)
{
string url = baseURL + "/envelopes/" + envelopeID + "/documents";
string requestBody =
// "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" + "\r\n" +
// "<documents>" + "\r\n" +
"<document>" + "\r\n" +
"<documentId>10</documentId>" + "\r\n" +
"<name>" + attachmentname + "</name>" + "\r\n" +
"<order>2</order>" + "\r\n" +
"<FileExtension>" + System.IO.Path.GetExtension(attachmentname).Replace(".", "").ToLower() + "</FileExtension>" + "\r\n" +
"<documentBase64>" + System.Convert.ToBase64String(attachment, 0, attachment.Length) + "</documentBase64>" + "\r\n" +
"</document>" + "\r\n" +
// "</documents>" + "\r\n" +
// "</envelopeDefinition>" + "\r\n" +
"";
//requestBody = requestBody.Replace("\r\n", "");
HttpWebRequest request = initializeRequest(url, "PUT", requestBody, email, password);
string response = getResponseBody(request);
}
答案 0 :(得分:0)
所以在这里要小心你的问题的措辞 - 如上所述,“附件”在DocuSign平台中被称为“签名者附件”,而这些只能通过个人收件人的签名者附件标签添加。
另一方面,我们通常将“文档”称为“信封文档”,如上所述,当信封处于草稿状态时,您可以将文档添加到信封中:
REST API v2 Guide - Add Documents to Draft Envelope
这是您要对PUT
网址进行的/accounts/{accountId}/envelopes/{envelopeId}/documents
来电。这是一个完整的C#代码示例(从DocuSign API演练中复制):
using System;
using System.IO;
using System.Net;
using System.Xml;
using System.Xml.Linq;
namespace DocuSignAPITest
{
public class AddDocumentToEnvelope
{
public static void Main ()
{
//---------------------------------------------------------------------------------------------------
// ENTER VALUES FOR THE FOLLOWING 6 VARIABLES:
//---------------------------------------------------------------------------------------------------
string username = "***"; // your account email
string password = "***"; // your account password
string integratorKey = "***"; // your account Integrator Key (found on Preferences -> API page)
string documentName = "***"; // copy document with same name and extension into project directory (i.e. "test.pdf")
string envelopeId = "***"; // GUID of envelope we will add document to
string contentType = "application/pdf"; // default content type is PDF
//---------------------------------------------------------------------------------------------------
// 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 from response body
baseURL = parseDataFromResponse(response, "baseUrl");
//--- display results
Console.WriteLine("\nAPI Call Result: \n\n" + prettyPrintXml(response));
//============================================================================
// STEP 2 - Add document to draft envelope
//============================================================================
// append "/envelopes/{envelopeId}/documents" to baseURL
url = baseURL + "/envelopes/" + envelopeId + "/documents";
// construct the request body
string jsonBody =
"{\"documents\": [" +
"{\"documentId\": \"2\"," +
"\"name\": \"test.pdf\"," +
"\"order\": \"2\"" +
"}]" +
"}";
Console.WriteLine("\nJSON: \n\n" + jsonBody);
// set request url, method, headers. Don't set the body yet, we'll set that separelty after
// we read the document bytes and configure the rest of the multipart/form-data request
request = initializeRequest( url, "PUT", null, username, password, integratorKey);
// some extra config for this api call
configureMultiPartFormDataRequest(request, jsonBody, documentName, contentType);
// read the http response
response = getResponseBody(request);
//--- display results
Console.WriteLine("\nAPI Call Result: \n\n" + prettyPrintXml(response));
// Console.WriteLine("\nAPI Call Result: \n\n" + 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 void configureMultiPartFormDataRequest(HttpWebRequest request, string jsonBody, string docName, string contentType)
{
// overwrite the default content-type header and set a boundary marker
request.ContentType = "multipart/form-data; boundary=BOUNDARY";
// start building the multipart request body
string requestBodyStart = "\r\n\r\n--BOUNDARY\r\n" +
"Content-Type: application/json\r\n" +
"Content-Disposition: form-data\r\n" +
"\r\n" +
jsonBody + "\r\n\r\n--BOUNDARY\r\n" + // our json formatted request body
"Content-Type: " + contentType + "\r\n" +
"Content-Disposition: file; filename=\"" + docName + "\"; documentId=2\r\n" +
"\r\n";
string requestBodyEnd = "\r\n--BOUNDARY--\r\n\r\n";
// read contents of provided document into the request stream
FileStream fileStream = File.OpenRead(docName);
// write the body of the request
byte[] bodyStart = System.Text.Encoding.UTF8.GetBytes(requestBodyStart.ToString());
byte[] bodyEnd = System.Text.Encoding.UTF8.GetBytes(requestBodyEnd.ToString());
Stream dataStream = request.GetRequestStream();
dataStream.Write(bodyStart, 0, requestBodyStart.ToString().Length);
// Read the file contents and write them to the request stream. We read in blocks of 4096 bytes
byte[] buf = new byte[4096];
int len;
while ((len = fileStream.Read(buf, 0, 4096) ) > 0) {
dataStream.Write(buf, 0, len);
}
dataStream.Write(bodyEnd, 0, requestBodyEnd.ToString().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