首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Zoho和DocuSign API尝试“发送文档以供签名-从模板”时出现415个错误

使用Zoho和DocuSign API尝试“发送文档以供签名-从模板”时出现415个错误
EN

Stack Overflow用户
提问于 2014-10-20 22:02:41
回答 1查看 350关注 0票数 0

我正在尝试设置一个Zoho应用程序,该应用程序将请求从模板创建的信封上的签名。我可以使用这个工具来完成这个任务,但是当我尝试使用Zoho的postURL()函数做同样的事情时,我从DocuSign得到了以下响应:

代码语言:javascript
复制
Response Code = 415
Response Text = HTTP Error

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

以下是我的Creator代码:

代码语言:javascript
复制
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;
}

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

代码语言:javascript
复制
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或DocuSign的任何人能帮我弄清楚我要做什么才能从Creator应用程序中获得与我上面链接的DocuSign API测试器相同的结果吗?

EN

回答 1

Stack Overflow用户

发布于 2014-10-21 03:51:10

问题在于您发送的请求内容类型和请求主体。默认情况下,如果不在Content-Type API调用中设置DocuSign头,则默认为application/json。你设置的请求体..。

代码语言:javascript
复制
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。因此,请查看具有9个API使用的示例Python代码的API演练,包括从模板发送文档:

http://iodocs.docusign.com/apiwalkthroughs

例如,下面是从模板发送文档的Python代码:

代码语言:javascript
复制
# 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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26475674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档