我正在尝试设置一个Zoho Creator应用程序,该应用程序将在从模板创建的信封上请求签名。我可以使用this tool来做这件事,但是当我尝试使用Zoho Creator的postURL()函数做同样的事情时,我从DocuSign得到以下回复:
Response Code = 415
Response Text = HTTP Error
This post似乎描述了完全相同的错误。给出的回复不清楚,我找不到应该更新的文档。
以下是我的一些创作者代码:
void test3()
{
// Login
username = "XXX";
usernameEmail = "XXX";
password = "XXX";
integratorKey = "XXX";
templateId = "XXX";
authenticateStr = "<DocuSignCredentials><Username>" + username + "</Username><Password>" + password + "</Password><IntegratorKey>" + integratorKey + "</IntegratorKey></DocuSignCredentials>";
loginUrl = "https://demo.docusign.net/restapi/v2/login_information";
loginHeaders = { "X-DocuSign-Authentication" : authenticateStr, "Accept" : "application/json" };
loginGet = getUrl(loginUrl, loginHeaders,false);
loginResponseCode = loginGet.get("responseCode");
loginResponseText = loginGet.get("responseText");
if (loginResponseCode != "200")
{
info "Error calling webservice; status is " + loginResponseCode;
}
创建者无法正确处理响应,所以我必须在此处清理它
loginResponseText = loginResponseText.replaceAll("\r\n","");
loginResponseText = loginResponseText.getSuffix("[");
loginResponseText = loginResponseText.getPrefix("]");
loginResponseMap = loginResponseText.toMap();
info loginResponseMap;
baseUrl = loginResponseMap.get("baseUrl");
accountID = loginResponseMap.get(("accountId"));
url = baseUrl + "/envelopes";
headers = map();
headers.put("X-DocuSign-Authentication", "{\"Username\":\"XXX\",\"Password\":\"XXX\",\"IntegratorKey\":\"XXX\"}");
requestBody2 = "{\n \"envelopeDefinition\" : \"{\n \"-xmlns\" : \"http://www.docusign.com/restapi\",\n =\"xmlns:i\":\"http://www.w3.org/2001/XMLSchema-instance\",\n \"emailSubject\": \"test email subject\",\n \"emailBlurb\": \"test email blurb\",\n \"templateId\": \"1D489D22-55D9-4320-8C16-28DE11C4AB09\",\n \"status\": \"created\",\n \"messageLock\": \"false\"\n}}";
envelopePOST = postUrl(url,requestBody2,headers,false);
postResponseCode = envelopePOST.get("responseCode");
postResponseText = envelopePOST.get("responseText");
info "envelopePOST = " + envelopePOST;
info "Response Code = " + postResponseCode;
info "Response Text = " + postResponseText;
}
来自Zoho Creator或DocuSign的任何人都可以帮我弄清楚我必须做些什么才能从我上面链接的DocuSign API测试器获得的Creator应用程序获得相同的结果?
答案 0 :(得分:0)
问题在于您发出的请求内容类型和请求正文。默认情况下,如果您未在DocuSign API调用中设置Content-Type
标头,则默认为application/json
。您正在设置的请求正文......
requestBody2 = "{\n \"envelopeDefinition\" : \"{\n \"-xmlns\" : \"http://www.docusign.com/restapi\",\n =\"xmlns:i\":\"http://www.w3.org/2001/XMLSchema-instance\",\n \"emailSubject\": \"test email subject\",\n \"emailBlurb\": \"test email blurb\",\n \"templateId\": \"1D489D22-55D9-4320-8C16-28DE11C4AB09\",\n \"status\": \"created\",\n \"messageLock\": \"false\"\n}}";
无效。看起来你正在使用xml和json的组合,DocuSign不会接受。
你经历过DocuSign Developer Center吗?如果您通过“快速入门”部分,它最终将转到API TOOLS部分,该部分有两个重要的工具,在这里将会有很大的帮助。我猜你的代码是基于你使用Python的。因此,请查看API演练,其中包含9个API用例的示例Python代码,包括从模板发送文档:
http://iodocs.docusign.com/apiwalkthroughs
例如,以下是用于从模板发送文档的Python代码:
# DocuSign API Walkthrough 01 (PYTHON) - Request Signature from Template
import sys, httplib2, json;
# Enter your info:
username = "***";
password = "***";
integratorKey = "***";
templateId = "***";
authenticateStr = "<DocuSignCredentials>" \
"<Username>" + username + "</Username>" \
"<Password>" + password + "</Password>" \
"<IntegratorKey>" + integratorKey + "</IntegratorKey>" \
"</DocuSignCredentials>";
#
# STEP 1 - Login
#
url = 'https://demo.docusign.net/restapi/v2/login_information'
headers = {'X-DocuSign-Authentication': authenticateStr, 'Accept': 'application/json'}
http = httplib2.Http()
response, content = http.request(url, 'GET', headers=headers)
status = response.get('status');
if (status != '200'):
print("Error calling webservice, status is: %s" % status); sys.exit();
# get the baseUrl and accountId from the response body
data = json.loads(content);
loginInfo = data.get('loginAccounts');
D = loginInfo[0];
baseUrl = D['baseUrl'];
accountId = D['accountId'];
#--- display results
print ("baseUrl = %s\naccountId = %s" % (baseUrl, accountId));
#
# STEP 2 - Create an Envelope with a Recipient and Send...
#
#construct the body of the request in JSON format
requestBody = "{\"accountId\": \"" + accountId + "\"," + \
"\"status\": \"sent\"," + \
"\"emailSubject\": \"API Call for sending signature request from template\"," + \
"\"emailBlurb\": \"This comes from Python\"," + \
"\"templateId\": \"" + templateId + "\"," + \
"\"templateRoles\": [{" + \
"\"email\": \"" + username + "\"," + \
"\"name\": \"Name\"," + \
"\"roleName\": \"Role\" }] }";
# append "/envelopes" to baseURL and use in the request
url = baseUrl + "/envelopes";
headers = {'X-DocuSign-Authentication': authenticateStr, 'Accept': 'application/json'}
http = httplib2.Http()
response, content = http.request(url, 'POST', headers=headers, body=requestBody);
status = response.get('status');
if (status != '201'):
print("Error calling webservice, status is: %s" % status); sys.exit();
data = json.loads(content);
envId = data.get('envelopeId');
#--- display results
print ("Signature request sent! EnvelopeId is: %s\n" % envId);