{errorCode:'INVALID_REQUEST_BODY',当试图发送信封

我正在尝试使用模板发送信封。 我使用表单数据来捕获这个调用所需的所有字段。 我创build了下面的对象,然后附加从用户添加值。 然后发送通过JSON.stringify之前发送到http post。 出于某种原因仍然收到错误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": "" } ] } } ] }]; 

我创build它,并使用从表单提交的用户数据追加它。 这是我如何追加对象。

  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); }); 

       

网上收集的解决方案 "{errorCode:'INVALID_REQUEST_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;