You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用DocuSign SDK创建信封时遭遇404错误求助

在Node.js中使用DocuSign SDK创建信封时遭遇404错误

我尝试在Node.js环境下用DocuSign SDK从模板生成信封,但不管是用SDK自带的方法还是直接用Axios调用API,都返回404错误,响应内容是一段HTML提示。

我的代码

const {email, name, templateId} = body;
const token = await DocuSign.token();
const dsAPIClient = new ApiClient();
dsAPIClient.setBasePath(DOCUSIGN_BASE_PATH as string);
dsAPIClient.addDefaultHeader('Authorization', `Bearer ${token}`);
const envelopeApi = new docusign.EnvelopesApi(dsAPIClient);
const envelope = this.makeEnvelope({email, name, templateId});
console.log(envelope);
// const result = await envelopeApi.createEnvelope(ACCOUNT_ID as string, {
//   envelopeDefinition: {},
// });
const result = await axios.post(
  `${DOCUSIGN_BASE_PATH}/v2.1/accounts/${ACCOUNT_ID}/envelopes`,
  envelope,
  {
    headers: {
      Authorization: `Bearer ${token}`,
    },
  }
);
// console.log('This is the result', result);
return result.data;

错误信息

两种调用方式都会返回如下错误:

Symbol(kOutHeaders)]: [Object: null prototype]
    '  <h2>404 - File or directory not found.</h2>\r\n' +
    '  <h3>The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3>\r\n' +
    ' </fieldset></div>\r\n' +
    '</div>\r\n' +
    '</body>\r\n' +
    '</html>\r\n'
},
isAxiosError: true,
toJSON: [Function: toJSON]

排查与解决步骤

  1. 核对基础路径DOCUSIGN_BASE_PATH
    • 沙箱环境必须用https://demo.docusign.net/restapi,生产环境用https://www.docusign.net/restapi,别加多余后缀或漏写路径。
  2. 确认账号IDACCOUNT_ID有效性
    • 检查账号ID是否拼写正确,可登录DocuSign控制台查看自己的账号ID。
  3. 检查makeEnvelope生成的信封结构
    • 从模板创建信封必须包含templateId、templateRoles等必填字段,打印出来的envelope要符合DocuSign的EnvelopeDefinition规范,结构错误可能导致API路径解析异常。
  4. 避免URL拼接的斜杠问题
    • 如果DOCUSIGN_BASE_PATH末尾带斜杠,拼接后会出现//v2.1这种无效路径,用URL对象拼接更稳妥:
      const url = new URL(`v2.1/accounts/${ACCOUNT_ID}/envelopes`, DOCUSIGN_BASE_PATH);
      const result = await axios.post(url.toString(), envelope, { headers: { Authorization: `Bearer ${token}` } });
      
  5. 验证Token有效性
    • 虽然404通常不是权限问题,但过期或无效Token可能引发异常响应,可调用GET ${DOCUSIGN_BASE_PATH}/v2.1/accounts/${ACCOUNT_ID}/users/me验证Token是否可用。

内容的提问来源于stack exchange,提问作者Gurdeep Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 12:05:22