发送nodejs sdk之前,填充预填充图

发布于 2025-02-11 22:39:29 字数 2374 浏览 4 评论 0原文

我们如何使用DocuSign的Nodejs SDK填充预填充图? 这是流程。我在第5号失败。

  1. 从项目数据库中获取数据。
  2. DocuSign身份验证以获取 AccountId
  3. 从模板创建信封草稿// {状态:“创建”}我可以确认它是我帐户中的草稿。
  4. 获取 kenloveedid
  5. 使用 AccountIdId ChempectedId 编辑字段的EnlovingApi.CreateDocumentTabs。

这是代码。我不确定我是否正在使用错误的API,但这是我发现的最接近的API。但是,它返回“不良请求”。

这是我的代码失败:

    if (envelopeId) {
      console.log(accountId, envelopeId, tabs);
      const res = await envelopesApi
        .createDocumentTabs(accountId, envelopeId, '1', getTabs("hello"));
      console.log(res);
    }

我尝试了标签的差异格式,这是我在getTabs(projname:string)funtion上尝试的一些。

a)

    const prefillTabs = {
            textTabs: [
              {
                'anchorString': '/koujimei/',
                'anchorUnits': 'pixels',
                'anchorXOffset': '20',
                'anchorYOffset': '10',
                'scaleValue': '1.5',
                'name': 'projName',
                'value': projName,
              },
            ],
          };
          return JSON.stringify(prefillTabs)

b)这个与文档相匹配吗?

     const prefillTabs = {
        prefillTabs: {
          textTabs: [
            {
              'anchorString': '/koujimei/',
              'anchorUnits': 'pixels',
              'anchorXOffset': '20',
              'anchorYOffset': '10',
              'scaleValue': '1.5',
              'name': 'projName',
              'value': projName,
            },
          ],
        },
      };
   return JSON.stringify(prefillTabs);

c)

      const prefillTabs = {
        tabs: {
          prefillTabs: {
            textTabs: [
              {
                'anchorString': '/koujimei/',
                'anchorUnits': 'pixels',
                'anchorXOffset': '20',
                'anchorYOffset': '10',
                'scaleValue': '1.5',
                'name': 'projName',
                'value': projName,
              },
            ],
          },
        },
      };
      return JSON.stringify(prefillTabs);

我还尝试直接使用无弦的对象,但是Typescript表示它需要字符串。

文档还说第四个参数是可选的,但仍然失败了“不良请求”。

const res = await envelopesApi
        .createDocumentTabs(accountId, envelopeId, '1');

How do we populate prefillTabs using docusign's nodejs sdk?
Here is the flow.I am failing at No. 5.

  1. Fetch data from the projects database.
  2. Docusign authentication to get accountId
  3. Create envelope draft from template // {status: "created"} I can confirm that it is draft in my account.
  4. Get the envelopedId.
  5. use envelopeAPI.createDocumentTabs with accountId and envelopedId to edit fields.

Here is the code. I am not sure if I am using the wrong API, but it is the closest I found. However it returns "Bad Request".

Here is my code that is failing :

    if (envelopeId) {
      console.log(accountId, envelopeId, tabs);
      const res = await envelopesApi
        .createDocumentTabs(accountId, envelopeId, '1', getTabs("hello"));
      console.log(res);
    }

I tried diffent format for the tabs here are some I tried at my getTabs(projName: string) funtion.

A)

    const prefillTabs = {
            textTabs: [
              {
                'anchorString': '/koujimei/',
                'anchorUnits': 'pixels',
                'anchorXOffset': '20',
                'anchorYOffset': '10',
                'scaleValue': '1.5',
                'name': 'projName',
                'value': projName,
              },
            ],
          };
          return JSON.stringify(prefillTabs)

B) This one matches the docs?

     const prefillTabs = {
        prefillTabs: {
          textTabs: [
            {
              'anchorString': '/koujimei/',
              'anchorUnits': 'pixels',
              'anchorXOffset': '20',
              'anchorYOffset': '10',
              'scaleValue': '1.5',
              'name': 'projName',
              'value': projName,
            },
          ],
        },
      };
   return JSON.stringify(prefillTabs);

C)

      const prefillTabs = {
        tabs: {
          prefillTabs: {
            textTabs: [
              {
                'anchorString': '/koujimei/',
                'anchorUnits': 'pixels',
                'anchorXOffset': '20',
                'anchorYOffset': '10',
                'scaleValue': '1.5',
                'name': 'projName',
                'value': projName,
              },
            ],
          },
        },
      };
      return JSON.stringify(prefillTabs);

I also tried directly using the objects without stringify, but Typescript says it requires string.

Also docs say that 4th parameter is optional but it still fails "Bad Request".

const res = await envelopesApi
        .createDocumentTabs(accountId, envelopeId, '1');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经大条 2025-02-18 22:39:30

这是一个预填充选项卡通过API请求构建器实时示例您可以更改输出的输出node.sdk的工具的语言。

这是一个工作示例:

#!/usr/bin/env node
 // DocuSign API Request Builder example. Generated: Tue, 05 Jul 2022 20:44:20 GMT
 // DocuSign Ⓒ 2022. MIT License -- https://opensource.org/licenses/MIT
'use strict';
const fse = require('fs-extra')
    , path = require('path')
    , docusign = require('docusign-esign')
    , baseUri = 'https://demo.docusign.net/'
      // Note: the accessToken is for testing and is temporary. It is only good for 8 hours from the time you 
      //       authenticated with API Request Builder. In production, use an OAuth flow to obtain access tokens.
    , accessToken = '..-7mT-4Gah3tduerH---...'
    , accountId = '...'
    , documentDirectory = '.'; // The directory with your documents
// Send the envelope
async function sendDocuSignEnvelope () {
    let signHereTab1 = docusign.SignHere.constructFromObject({
        anchorString: "/sig1/",  
        anchorUnits: "pixels",  
        anchorXOffset: "20" 
        });
    let signHereTabs1 = [signHereTab1];
    let tabs1 = docusign.Tabs.constructFromObject({
        signHereTabs: signHereTabs1 
        });
    let signer1 = docusign.Signer.constructFromObject({
        clientUserId: "1000",  
        email: "[email protected]",  
        name: "Signer's name",  
        recipientId: "1",  
        tabs: tabs1 
        });
    let signers1 = [signer1];
    let recipients1 = docusign.Recipients.constructFromObject({
        signers: signers1 
        });
    let textTab1 = docusign.Text.constructFromObject({
        anchorString: "/field1/ ",  
        bold: "true",  
        font: "Garamond",  
        fontColor: "BrightBlue",  
        fontSize: "Size14",  
        value: "This field and the following are all \"prefill\" fields: " 
        });
    let textTab2 = docusign.Text.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "0",  
        anchorYOffset: "30",  
        bold: "true",  
        font: "Garamond",  
        fontColor: "Black",  
        fontSize: "Size12",  
        value: "Checkbox:" 
        });
    let textTab3 = docusign.Text.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "90",  
        anchorYOffset: "30",  
        bold: "true",  
        font: "Garamond",  
        fontColor: "Black",  
        fontSize: "Size12",  
        value: "Radio button:" 
        });
    let textTab4 = docusign.Text.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "0",  
        anchorYOffset: "60",  
        bold: "true",  
        font: "Garamond",  
        fontColor: "Black",  
        fontSize: "Size12",  
        value: "Sender name:" 
        });
    let textTab5 = docusign.Text.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "190",  
        anchorYOffset: "60",  
        bold: "true",  
        font: "Garamond",  
        fontColor: "Black",  
        fontSize: "Size12",  
        value: "Sender company:" 
        });
    let textTabs1 = [textTab1, textTab2, textTab3, textTab4, textTab5];
    let checkboxTab1 = docusign.Checkbox.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "70",  
        anchorYOffset: "30",  
        fontSize: "Size14",  
        selected: "true" 
        });
    let checkboxTabs1 = [checkboxTab1];
    let radio1 = docusign.Radio.constructFromObject({
        anchorString: "/field1/",  
        anchorXOffset: "185",  
        anchorYOffset: "30",  
        fontSize: "Size14",  
        selected: "true" 
        });
    let radios1 = [radio1];
    let radioGroupTab1 = docusign.RadioGroup.constructFromObject({
        radios: radios1 
        });
    let radioGroupTabs1 = [radioGroupTab1];
    let senderNameTab1 = docusign.SenderName.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "90",  
        anchorYOffset: "58",  
        font: "Garamond",  
        fontColor: "DarkGreen",  
        fontSize: "Size12" 
        });
    let senderNameTabs1 = [senderNameTab1];
    let senderCompanyTab1 = docusign.SenderCompany.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "310",  
        anchorYOffset: "58",  
        font: "Garamond",  
        fontColor: "DarkGreen",  
        fontSize: "Size12" 
        });
    let senderCompanyTabs1 = [senderCompanyTab1];
    let prefillTabs1 = docusign.PrefillTabs.constructFromObject({
        checkboxTabs: checkboxTabs1,  
        radioGroupTabs: radioGroupTabs1,  
        senderCompanyTabs: senderCompanyTabs1,  
        senderNameTabs: senderNameTabs1,  
        textTabs: textTabs1 
        });
    let tabs2 = docusign.Tabs.constructFromObject({
        prefillTabs: prefillTabs1 
        });
    let document1 = docusign.Document.constructFromObject({
        documentId: "1",  
        fileExtension: "pdf",  
        documentBase64: await readDocFileB64("anchorfields.pdf"),  // filename is anchorfields.pdf
        name: "Example document",  
        tabs: tabs2 
        });
    let documents1 = [document1];
    let envelopeDefinition = docusign.EnvelopeDefinition.constructFromObject({
        documents: documents1,  
        emailSubject: "Please sign the attached document",  
        recipients: recipients1,  
        status: "sent" 
        });
 
    try {
        const dsApi = new docusign.ApiClient();
        dsApi.addDefaultHeader('Authorization', 'Bearer ' + accessToken);
        dsApi.setBasePath(baseUri + 'restapi');
        const envelopesApi = new docusign.EnvelopesApi(dsApi);
        const envResults = await envelopesApi.createEnvelope(accountId, 
            {envelopeDefinition: envelopeDefinition});
        console.log (`Create envelope results: ${JSON.stringify(envResults, null, '    ')}`);
        console.log (`The envelopeId is ${envResults.envelopeId}`);
        return envResults.envelopeId;
    } catch (e) {
        console.log (`Error from DocuSign create envelope: ` +
           `${(e && e.response && JSON.stringify(e.response.body))||e}`);
        return false
    }
}

Here is a PreFill tabs live example via the API Request Builder You can change the output language of the tool to the Node.SDK.

Here is a working example:

#!/usr/bin/env node
 // DocuSign API Request Builder example. Generated: Tue, 05 Jul 2022 20:44:20 GMT
 // DocuSign Ⓒ 2022. MIT License -- https://opensource.org/licenses/MIT
'use strict';
const fse = require('fs-extra')
    , path = require('path')
    , docusign = require('docusign-esign')
    , baseUri = 'https://demo.docusign.net/'
      // Note: the accessToken is for testing and is temporary. It is only good for 8 hours from the time you 
      //       authenticated with API Request Builder. In production, use an OAuth flow to obtain access tokens.
    , accessToken = '..-7mT-4Gah3tduerH---...'
    , accountId = '...'
    , documentDirectory = '.'; // The directory with your documents
// Send the envelope
async function sendDocuSignEnvelope () {
    let signHereTab1 = docusign.SignHere.constructFromObject({
        anchorString: "/sig1/",  
        anchorUnits: "pixels",  
        anchorXOffset: "20" 
        });
    let signHereTabs1 = [signHereTab1];
    let tabs1 = docusign.Tabs.constructFromObject({
        signHereTabs: signHereTabs1 
        });
    let signer1 = docusign.Signer.constructFromObject({
        clientUserId: "1000",  
        email: "[email protected]",  
        name: "Signer's name",  
        recipientId: "1",  
        tabs: tabs1 
        });
    let signers1 = [signer1];
    let recipients1 = docusign.Recipients.constructFromObject({
        signers: signers1 
        });
    let textTab1 = docusign.Text.constructFromObject({
        anchorString: "/field1/ ",  
        bold: "true",  
        font: "Garamond",  
        fontColor: "BrightBlue",  
        fontSize: "Size14",  
        value: "This field and the following are all \"prefill\" fields: " 
        });
    let textTab2 = docusign.Text.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "0",  
        anchorYOffset: "30",  
        bold: "true",  
        font: "Garamond",  
        fontColor: "Black",  
        fontSize: "Size12",  
        value: "Checkbox:" 
        });
    let textTab3 = docusign.Text.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "90",  
        anchorYOffset: "30",  
        bold: "true",  
        font: "Garamond",  
        fontColor: "Black",  
        fontSize: "Size12",  
        value: "Radio button:" 
        });
    let textTab4 = docusign.Text.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "0",  
        anchorYOffset: "60",  
        bold: "true",  
        font: "Garamond",  
        fontColor: "Black",  
        fontSize: "Size12",  
        value: "Sender name:" 
        });
    let textTab5 = docusign.Text.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "190",  
        anchorYOffset: "60",  
        bold: "true",  
        font: "Garamond",  
        fontColor: "Black",  
        fontSize: "Size12",  
        value: "Sender company:" 
        });
    let textTabs1 = [textTab1, textTab2, textTab3, textTab4, textTab5];
    let checkboxTab1 = docusign.Checkbox.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "70",  
        anchorYOffset: "30",  
        fontSize: "Size14",  
        selected: "true" 
        });
    let checkboxTabs1 = [checkboxTab1];
    let radio1 = docusign.Radio.constructFromObject({
        anchorString: "/field1/",  
        anchorXOffset: "185",  
        anchorYOffset: "30",  
        fontSize: "Size14",  
        selected: "true" 
        });
    let radios1 = [radio1];
    let radioGroupTab1 = docusign.RadioGroup.constructFromObject({
        radios: radios1 
        });
    let radioGroupTabs1 = [radioGroupTab1];
    let senderNameTab1 = docusign.SenderName.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "90",  
        anchorYOffset: "58",  
        font: "Garamond",  
        fontColor: "DarkGreen",  
        fontSize: "Size12" 
        });
    let senderNameTabs1 = [senderNameTab1];
    let senderCompanyTab1 = docusign.SenderCompany.constructFromObject({
        anchorString: "/field1/ ",  
        anchorXOffset: "310",  
        anchorYOffset: "58",  
        font: "Garamond",  
        fontColor: "DarkGreen",  
        fontSize: "Size12" 
        });
    let senderCompanyTabs1 = [senderCompanyTab1];
    let prefillTabs1 = docusign.PrefillTabs.constructFromObject({
        checkboxTabs: checkboxTabs1,  
        radioGroupTabs: radioGroupTabs1,  
        senderCompanyTabs: senderCompanyTabs1,  
        senderNameTabs: senderNameTabs1,  
        textTabs: textTabs1 
        });
    let tabs2 = docusign.Tabs.constructFromObject({
        prefillTabs: prefillTabs1 
        });
    let document1 = docusign.Document.constructFromObject({
        documentId: "1",  
        fileExtension: "pdf",  
        documentBase64: await readDocFileB64("anchorfields.pdf"),  // filename is anchorfields.pdf
        name: "Example document",  
        tabs: tabs2 
        });
    let documents1 = [document1];
    let envelopeDefinition = docusign.EnvelopeDefinition.constructFromObject({
        documents: documents1,  
        emailSubject: "Please sign the attached document",  
        recipients: recipients1,  
        status: "sent" 
        });
 
    try {
        const dsApi = new docusign.ApiClient();
        dsApi.addDefaultHeader('Authorization', 'Bearer ' + accessToken);
        dsApi.setBasePath(baseUri + 'restapi');
        const envelopesApi = new docusign.EnvelopesApi(dsApi);
        const envResults = await envelopesApi.createEnvelope(accountId, 
            {envelopeDefinition: envelopeDefinition});
        console.log (`Create envelope results: ${JSON.stringify(envResults, null, '    ')}`);
        console.log (`The envelopeId is ${envResults.envelopeId}`);
        return envResults.envelopeId;
    } catch (e) {
        console.log (`Error from DocuSign create envelope: ` +
           `${(e && e.response && JSON.stringify(e.response.body))||e}`);
        return false
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文