gpt4 book ai didi

javascript - { 尝试发送信封时出现错误代码 : 'INVALID_REQUEST_BODY' ,

转载 作者:行者123 更新时间:2023-11-30 21:13:53 25 4
gpt4 key购买 nike

我正在尝试使用模板发送信封。我使用表单数据来捕获此调用所需的所有字段。我创建了下面的对象,然后追加以添加来自用户的值。然后在发送到 http post 之前通过 JSON.stringify 发送。由于某种原因仍然收到错误 INVALID_BODY_REQUEST

var data = [

{
"documents": [
{

"documentId": "27730895",
"fileExtension": "pdf",
"name": "Top Level Staging",
"order": "1"
}
],
"emailSubject": "Please Sign document",
"status": "sent",
"templateId": "4fda9b93-9c82-4f23-bd06-67f9b35f0183",
"templateRoles": [
{
"email": "",
"name": "",
"roleName": "Client",
"tabs": {
"textTabs": [
{
"documentId": "27730895",
"pageNumber": "1",
"tabLabel": "cPackage",
"value": ""
},
{
"documentId": "27730895",
"pageNumber": "1",
"tabLabel": "sDate",
"value": ""
},
{
"documentId": "27730895",
"pageNumber": "1",
"tabLabel": "pAddress",
"value": ""
},
{
"documentId": "27730895",
"pageNumber": "2",
"tabLabel": "rAmount",
"value": ""
}
]
}
}
]
}];

我使用从表单提交的用户数据创建并附加它。这是我附加对象的方式。

  var  contract_data = {    

cEmail:req.body.cEmail,
FullName:req.body.cName,
pAddress:req.body.pAddress,
cAmount:req.body.cAmount,
rAmount:req.body.rAmount,
dCompleted:req.body.dCompleted,
cDate:req.body.cDate,
cPackage:req.body.cPackage

};

/data[0].templateRoles[1] = contract_data.cEmail;
data[0].templateRoles[2] = contract_data.FullName;
data[0].templateRoles[0].tabs.textTabs[0].value = contract_data.cPackage;
data[0].templateRoles[0].tabs.textTabs[1].value = contract_data.dCompleted;
data[0].templateRoles[0].tabs.textTabs[2].value = contract_data.pAdress;
data[0].templateRoles[0].tabs.textTabs[3].value = contract_data.rAmount;

然后我像这样通过 JSON.stringify() 发送该数据数组

var body = JSON.stringify(data) 

随请求发送到帖子

 request({
headers:{"X-DocuSign-Authentication":creds},
url: "https://demo.docusign.net/restapi/v2/accounts/3465212/envelopes",
json: true, // <--Very important!!!
body: body,
method: "POST",

}, function (error, response, body){
console.log(response.body);
});

最佳答案

请求体的根不能是数组。

改变如下。删除了 []

var data = 
{
"documents": [
{
//Removed document properties for brevity
}
],
"emailSubject": "Please Sign document",
"status": "sent",
"templateId": "4fda9b93-9c82-4f23-bd06-67f9b35f0183",
"templateRoles": [
{
//Removed template roles for brevity
}
]
};

然后按如下方式更新模板 Angular 色。使用 data 而不是 data[0] 因为它不再是数组。

var tRole = data.templateRoles[0];
tRole.email = contract_data.cEmail;
tRole.name = contract_data.FullName;
tRole.tabs.textTabs[0].value = contract_data.cPackage;
tRole.tabs.textTabs[1].value = contract_data.dCompleted;
tRole.tabs.textTabs[2].value = contract_data.pAdress;
tRole.tabs.textTabs[3].value = contract_data.rAmount;

关于javascript - { 尝试发送信封时出现错误代码 : 'INVALID_REQUEST_BODY' ,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45868941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com