[英]Docusign for Salesforce Javascript or API ? Need to pass a document ID
[英]DocuSign API - JavaScript
下午! 我是JavaScript和DocuSign API的新手。 我尝试按照示例进行操作,但是遇到了ReferenceError。
为了进行测试,我在PC上文件夹的根目录中有async.js,fs.js,request.js和require.js以及测试HTML文档
HTML:
<html>
<head>
<script src="require.js"></script>
<script src="example.js"></script>
</head>
<body>
<div id="message"></div>
</body>
</html>
我收到以下错误:ReferenceError:未定义async async.waterfall(
以下是我从DocuSign网站获得的example.js代码,根据require函数周围的另一个错误对它进行了调整:
// Request Signature on a Document (JavaScript)
// To run this sample
// 1. Copy the file to your local machine and give .js extension (i.e. example.js)
// 2. Change "***" to appropriate values
// 3. Install async and request packages
// npm install async
// npm install request
// npm install fs
// 4. execute
// node example.js
//
//var async = require("async"), // async module
// request = require("request"), // request module
// fs = require("fs"); // fs module
require(["request"], function (request){});
require(["async"], function (async){});
require(["fs"], function (fs){});
var email = "email@email", // your account email
password = "apassword", // your account password
integratorKey = "akey", // your Integrator Key
(found on the Preferences -> API page)
recipientName = "Bob", // recipient (signer) name
documentName = "afile", // copy document with this name into same
directory!
baseUrl = ""; // we will retrieve this through the Login call
async.waterfall(
[
/////////////////////////////////////////////////////////////////////////////////////
// Step 1: Login (used to retrieve your accountId and baseUrl)
/////////////////////////////////////////////////////////////////////////////////////
function(next) {
var url = "https://demo.docusign.net/restapi/v2/login_information";
var body = ""; // no request body for login api call
// set request url, method, body, and headers
var options = initializeRequest(url, "GET", body, email, password);
// send the request...
request(options, function(err, res, body) {
if(!parseResponseBody(err, res, body)) {
return;
}
baseUrl = JSON.parse(body).loginAccounts[0].baseUrl;
next(null); // call next function
});
},
/////////////////////////////////////////////////////////////////////////////////////
// Step 2: Request Signature on a PDF Document
/////////////////////////////////////////////////////////////////////////////////////
function(next) {
var url = baseUrl + "/envelopes";
// following request body will place 1 signature tab 100 pixels to the right and
// 100 pixels down from the top left of the document that you send in the request
var body = {
"recipients": {
"signers": [{
"email": email,
"name": recipientName,
"recipientId": 1,
"tabs": {
"signHereTabs": [{
"xPosition": "100",
"yPosition": "100",
"documentId": "1",
"pageNumber": "1"
}]
}
}]
},
"emailSubject": 'DocuSign API - Signature Request on Document Call',
"documents": [{
"name": documentName,
"documentId": 1,
}],
"status": "sent",
};
// set request url, method, body, and headers
var options = initializeRequest(url, "POST", body, email, password);
// change default Content-Type header from "application/json" to "multipart/form-data"
options.headers["Content-Type"] = "multipart/form-data";
// configure a multipart http request with JSON body and document bytes
options.multipart = [{
"Content-Type": "application/json",
"Content-Disposition": "form-data",
"body": JSON.stringify(body),
}, {
"Content-Type": "application/pdf",
'Content-Disposition': 'file; filename="' + documentName + '";
documentId=1',
"body": fs.readFileSync(documentName),
}
];
// send the request...
request(options, function(err, res, body) {
parseResponseBody(err, res, body);
});
} // end function
]);
//***********************************************************************************************
// --- HELPER FUNCTIONS ---
//***********************************************************************************************
function initializeRequest(url, method, body, email, password) {
var options = {
"method": method,
"uri": url,
"body": body,
"headers": {}
};
addRequestHeaders(options, email, password);
return options;
}
///////////////////////////////////////////////////////////////////////////////////////////////
function addRequestHeaders(options, email, password) {
// JSON formatted authentication header (XML format allowed as well)
dsAuthHeader = JSON.stringify({
"Username": email,
"Password": password,
"IntegratorKey": integratorKey // global
});
// DocuSign authorization header
options.headers["X-DocuSign-Authentication"] = dsAuthHeader;
}
///////////////////////////////////////////////////////////////////////////////////////////////
function parseResponseBody(err, res, body) {
console.log("\r\nAPI Call Result: \r\n", JSON.parse(body));
if( res.statusCode != 200 && res.statusCode != 201) { // success statuses
console.log("Error calling webservice, status is: ", res.statusCode);
console.log("\r\n", err);
return false;
}
return true;
}
再次,我对此很陌生,因此,非常感谢您的帮助,在此先感谢您!
更新-在意识到我无法在QuickBase代码页上使用的node.js片段之后,我尝试了以下两个编码选项,但都没有起作用……任何想法我做错了什么?
var xhr = createCORSRequest('GET', urlLoginCall);
xhr.withCredentials = true;
xhr.setRequestHeader('X-DocuSign-Authentication', jsonLoginCall);
xhr.send();
xhr.onload = function() {
var responseText = xhr.responseText;
alert(responseText);
};
xhr.onerror = function() {
alert('There was an error!');
};
和
$.ajax({
type: 'GET',
url: urlLoginCall,
headers: {
'X-DocuSign-Authentication': jsonLoginCall
},
xhrFields: {
withCredentials: true
},
success: function() {
alert("success");
},
error: function() {
alert("failure");
}
});
通过Fidler,我总是将其作为请求标头:
OPTIONS /restapi/v2/login_information HTTP/1.1
Host: demo.docusign.net
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: https://twmts.quickbase.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36
Access-Control-Request-Headers: x-docusign-authentication
Accept: */*
Referer: https://twmts.quickbase.com/db/bhkhmzax6?a=dbpage&pageID=145
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
这作为响应头:
HTTP/1.1 200 OK
Cache-Control: no-cache
Date: Mon, 10 Mar 2014 12:15:48 GMT
Content-Length: 0
Strict-Transport-Security: max-age=7776000; includeSubDomains
没有返回XML或JSON。 我知道这一定很简单,我只是不明白,但是我花了很多时间tryig来确定我所缺少的东西,除了不使用node.js之外,我无法弄清楚。
您引用的DocuSign示例代码使用Node.js
模块,更具体地说,它使用request
, async
和fs
模块。 您似乎已经注释了导入所需的Node.js库的三行:
//var async = require("async"), // async module
// request = require("request"), // request module
// fs = require("fs"); // fs module
require
语句加载不同的模块,并且当您注释掉上面的代码时,它不知道async.waterfall函数是什么,因为它没有在任何地方声明。 要解决该问题,请尝试取消注释上面的代码,结果如下:
var async = require("async"), // async module
request = require("request"), // request module
fs = require("fs"); // fs module
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.