使用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]
排查与解决步骤
- 核对基础路径
DOCUSIGN_BASE_PATH- 沙箱环境必须用
https://demo.docusign.net/restapi,生产环境用https://www.docusign.net/restapi,别加多余后缀或漏写路径。
- 沙箱环境必须用
- 确认账号ID
ACCOUNT_ID有效性- 检查账号ID是否拼写正确,可登录DocuSign控制台查看自己的账号ID。
- 检查
makeEnvelope生成的信封结构- 从模板创建信封必须包含
templateId、templateRoles等必填字段,打印出来的envelope要符合DocuSign的EnvelopeDefinition规范,结构错误可能导致API路径解析异常。
- 从模板创建信封必须包含
- 避免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}` } });
- 如果
- 验证Token有效性
- 虽然404通常不是权限问题,但过期或无效Token可能引发异常响应,可调用
GET ${DOCUSIGN_BASE_PATH}/v2.1/accounts/${ACCOUNT_ID}/users/me验证Token是否可用。
- 虽然404通常不是权限问题,但过期或无效Token可能引发异常响应,可调用
内容的提问来源于stack exchange,提问作者Gurdeep Singh
相关产品推荐
相关产品推荐

