Node js,Docusign下载信封的签名文档

时间:2018-10-14 17:05:41

标签: docusignapi

axios({
method: 'get',
url: `https://demo.docusign.net/restapi/v2/accounts/{AccountID}/envelopes/{ID}/documents/1`,
headers: {
    'X-DocuSign-Authentication': JSON.stringify({
        "Username": docusign.username,
        "Password": docusign.password,
        "IntegratorKey": docusign.integratorKey
    }),
    'Content-Type': 'application/json'
},
}).then(response =>  {
    fs.writeFileSync('./i.pdf', response.data, {encoding: 'binary'})
}).catch(console.log)

使用上面的代码,我无法保存正确的文件,请问您对此有何帮助

2 个答案:

答案 0 :(得分:1)

Arjun我找到了解决方案,请检查以下代码。

let docuResponce = axios({
               method: 'get',
   url:`https://demo.docusign.net/restapi/v2/accounts/{AccountID}/envelopes/{ID}/documents/1`,
               headers: {
                        'X-DocuSign-Authentication': JSON.stringify({
                                 "Username": docusign.username,
                                  "Password": docusign.password,
                                  "IntegratorKey": docusign.integratorKey
                                }),
                        'Content-Type': 'application/pdf'
                      },
                  responseType: 'stream'
               });

    var fs = require('fs');
    var path = require('path');

    // file name
    var filename = envelopID + '_' + docusign.accountID + '.pdf';
    var tempFile = path.resolve(__dirname, filename); // file path

    // generate a file stream
    docu.data.pipe(fs.createWriteStream(tempFile));

    docu.data.on('end', () => {
        // file has been download
        res.status(200).json({ success: 'true', data: '' });
    });

    docu.data.on('error', (err) => {
        // error in download
        res.status(200).json({ success: 'false', data: '' });
    });

答案 1 :(得分:0)

  1. 您正在使用旧式身份验证,而不是使用更安全和现代的oauth。我建议您更改代码以使用JWT授予。
  2. 您正在使用v2.0 API。我建议您更改为使用API​​ v2.1