在进行api调用时Docusign传统标头错误

时间:2017-08-24 16:01:15

标签: node.js api authentication docusignapi

尝试为Docusign API使用旧版标头时收到错误。

这是我的代码

request({
    headers: {
        "X-DocuSign-Authentication": [{
            "Username": "zabie@toplevelstaging.com",
            "Password": "xxxxxxxx",
            "IntegratorKey": "xxxxxxxxxxx-11xxx2f567xxxx0dbxxxx2d"
        }]
    },
    url: "https://demo.docusign.net/restapi/v2/accounts/3465212/envelopes",
    json: true, // <--Very important!!!
    body: data,
    method: "POST",

}, function (error, response, body) {
    console.log(response.body);
});
console.log(data[0].templateRoles[0].tabs.textTabs[0].value);
console.log(data[0].templateRoles[0].roleName);
res.redirect('/contracts');

});

这是错误

{
    errorCode: 'INVALID_TOKEN_FORMAT',
    message: 'The security token format does not conform to expected schema.'
}

1 个答案:

答案 0 :(得分:2)

您传递的authheader不正确。请尝试以下方法。 SDK文档here

// create JSON formatted auth header
var creds = JSON.stringify({
  Username: "zabie@toplevelstaging.com",
  Password: "xxxxxxx",
  IntegratorKey: "xxxxxxxxxxx-11xxx2f567xxxx0dbxxxx2d"
});


request({
   headers: { "X-DocuSign-Authentication": creds },
   url: "https://demo.docusign.net/restapi/v2/accounts/3465212/envelopes",
   json: true, // <--Very important!!!
   body: data,
   method: "POST",
   }, function (error, response, body) {
    console.log(response.body);
});