DocuSign - 尝试创建信封时出现“未收到文档”错误消息

问题描述 投票:0回答:1

我正在构建一个 nextjs 应用程序,它也将使用 DocuSign 解决方案。

我现在的组织用户可以看到模板的预览(有效!),然后通过单击按钮,应该触发将文档发送给收件人的过程(并接收副本)。

这是相关方法:

export async function createAndSendEnvelope(
  templateId: string,
  projectOffer: any,
  orgUser: any,
  applicant: any,
): Promise<string> {
  try {
    const authInfo = await authenticate();
    const dsApi = new docusign.ApiClient();
    dsApi.setBasePath(authInfo.basePath);
    dsApi.addDefaultHeader("Authorization", "Bearer " + authInfo.accessToken);
    const envelopesApi = new docusign.EnvelopesApi(dsApi);

    console.log("Creating and sending envelope...");

    const envelope: docusign.EnvelopeDefinition = {
      templateId: templateId,
      status: "sent",
      emailSubject: `${projectOffer.title} - Contract for Signature`,
      templateRoles: [
        {
          email: applicant.email,
          name: `${applicant.firstName} ${applicant.lastName}`,
          roleName: "Applicant",
        },
        {
          email: orgUser.email,
          name: `${orgUser.firstName} ${orgUser.lastName}`,
          roleName: "Organization User",
        },
      ],
      customFields: {
        textCustomFields: [
          { name: "projectTitle", value: projectOffer.title },
          { name: "rate", value: projectOffer.rate.toString() },
        ],
      },
      recipients: {
        signers: [
          {
            email: applicant.email,
            name: `${applicant.firstName} ${applicant.lastName}`,
            recipientId: "1",
            roleName: "Applicant",
          },
        ],
        carbonCopies: [
          {
            email: orgUser.email,
            name: `${orgUser.firstName} ${orgUser.lastName}`,
            recipientId: "2",
            roleName: "Organization User",
          },
        ],
      },
    };

    const results = await envelopesApi.createEnvelope(authInfo.apiAccountId, {
      envelopeDefinition: envelope,
    });

    return results.envelopeId || "";
  } catch (error: any) {
    console.error(
      "Error creating and sending envelope:",
      error.response?.data || error.message,
    );
    throw error;
  }
}```


data: {
      errorCode: 'NO_DOCUMENT_RECEIVED',
      message: 'The document element did not contain the encoded document, or there is a problem with the encoding. No documents were found in the request.'
    }
  },
  status: 400

根据我所有的研究(例如这里:https://github.com/docusign/code-examples-node/blob/master/lib/eSignature/examples/useTemplate.js)我可以告诉你的一切需要使其发挥作用。

有人知道问题可能是什么吗?

它似乎没有使用模板,但需要文档的 base64 编码版本。

感谢一百万

next.js docusignapi docusign-sdk
1个回答
0
投票

感谢您使用 Docusign。

我们很欣赏代码示例。

一个可能的原因是使用此语法会创建一个新的空变量:

{envelopeDefinition: envelope}

 const results = await envelopesApi.createEnvelope(authInfo.apiAccountId, {
      envelopeDefinition: envelope,
    });

尝试使用

const results = await envelopesApi.createEnvelope(authInfo.apiAccountId, envelope);

使用之前修改过的变量。

您还可以检查您提供的 templateID 是否有效。

您可以使用 API 日志记录来查看使用本指南从代码发送到服务器的信息:

[https://support.docusign.com/s/document-item?language=en_US&bundleId=jux1643235969954&topicId=poz1578456669909.html&_LANG=enus][1]

此外,由于您使用的是模板并在 TemplateRoles 中提供了收件人信息,因此您可以删除代码中的“收件人”部分。

我们希望这会有所帮助。

致以诚挚的问候,

阿德里安 | Docusign 开发人员支持

© www.soinside.com 2019 - 2024. All rights reserved.