0

我正在尝试设置一个 Zoho Creator 应用程序,该应用程序将请求在从模板创建的信封上签名。我可以使用此工具执行此操作,但是当我尝试使用 Zoho Creator 的 postURL() 函数执行相同操作时,我从 DocuSign 收到以下响应:

Response Code = 415
Response Text = HTTP Error

这篇文章似乎描述了完全相同的错误。给出的回复不清楚,我找不到应该更新的文档。

这是我的一些创建者代码:

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;
}

Creator 无法正确处理响应,所以我必须在这里清理它

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 的任何人都可以帮我弄清楚我必须做什么才能从 Creator 应用程序中获得与我从上面链接到的 DocuSign API 测试器获得的相同结果吗?

4

1 回答 1

0

问题在于您发送的请求内容类型和请求正文。默认情况下,如果您未Content-Type在 DocuSign API 调用中设置标头,则默认为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 开发人员中心?如果您浏览快速入门部分,它最终会转到 API 工具部分,其中有两个重要的工具,在这里会有很大帮助。我根据您正在使用 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);
于 2014-10-21T03:51:10.237 回答