1

I am trying to create an Envelope in DocuSign with multiple documents using the DocuSign REST API, I'm using a multipart/form-data request, I use JSON to define the attributes of the envelope, I check my JSON and I think it is OK. Below that I define a multipart/mixed section where I set the header and PDF bytes of the documents. I receive a Bad Request error code that said "NO_DOCUMENT_RECEIVED" and have as message "The document element did not contain the encoded document, or there is a problem with the encoding. ". I post the request result from fiddler below:

// Request

POST https://demo.docusign.net/restapi/v2/accounts/295724/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"email","Password":"password","IntegratorKey":"key"}
Content-Type: multipart/form-data; boundary=9a56da749dc04804819460f6499ab80b
Accept: application/json
Host: demo.docusign.net
Content-Length: 31476
Expect: 100-continue

--9a56da749dc04804819460f6499ab80b
Content-Type: application/json
Content-Disposition: form-data

{"emailBlurb":"EMAIL BODY HERE OK OK","emailSubject":"EMAIL SUBJECT HERE IS MANDATORY","status":"sent","documents":[{"documentId":1,"name":"ABC.pdf"},{"documentId":2,"name":"AB.pdf"}],"recipients":{"signers":[{"email":"dn@brenock.com","name":"Dubhe","recipientId":"1","routingOrder":"1"},{"email":"dubhe.dnacimiento@gmail.com","name":"DubheF","recipientId":"2","routingOrder":"1"}]}}
--9a56da749dc04804819460f6499ab80b
Content-Disposition: form-data
Content-Type: multipart/mixed; boundary=e8bc9555e9634110bba63547b2552460

--e8bc9555e9634110bba63547b2552460
Content-Type: application/pdf
Content-Disposition: file; filename=ABC.pdf; documentId=1

<PDF Bytes Document 1>
--e8bc9555e9634110bba63547b2552460
Content-Type: application/pdf
Content-Disposition: file; filename=AB.pdf; documentId=2

<PDF BytesDocument Two>
--e8bc9555e9634110bba63547b2552460--
--9a56da749dc04804819460f6499ab80b--
dhernandez
  • 77
  • 3
  • 11
  • Hmm on the surface I don't see anything obviously wrong, are you sure the content-length value is being set correctly? Also are you positive both documents are valid PDFs? – Ergin Dec 11 '13 at 06:08

1 Answers1

0

You shouldn't need these lines that define a second boundary (or any of the subsequent references to that second boundary):

Content-Disposition: form-data
Content-Type: multipart/mixed; boundary=e8bc9555e9634110bba63547b2552460

Try removing that (and all subsequent references to boundary e8bc9555e9634110bba63547b2552460), so that your request looks like this:

POST https://demo.docusign.net/restapi/v2/accounts/295724/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"email","Password":"password","IntegratorKey":"key"}
Content-Type: multipart/form-data; boundary=9a56da749dc04804819460f6499ab80b
Accept: application/json
Host: demo.docusign.net
Content-Length: 31476
Expect: 100-continue

--9a56da749dc04804819460f6499ab80b
Content-Type: application/json
Content-Disposition: form-data

JSON_REQUEST_BODY_HERE
--9a56da749dc04804819460f6499ab80b
Content-Type:application/pdf
Content-Disposition: file; filename="ABC.pdf"; documentid=1 

DOCUMENT_1_BYTES_HERE
--9a56da749dc04804819460f6499ab80b
Content-Type:application/pdf
Content-Disposition: file; filename="AB.pdf"; documentid=2 

DOCUMENT_2_BYTES_HERE
--9a56da749dc04804819460f6499ab80b--
Kim Brandl
  • 13,125
  • 2
  • 16
  • 21
  • Interesting, I've actually tested this recently and had it work successfully using two boundaries and the multipart/mixed header as is in the question. I haven't had a chance to test the way you've listed here, will do so tomorrow... – Ergin Dec 11 '13 at 06:05
  • Hmmmm...I've never tested with two boundaries like the question shows. I've always done it the way I suggest in my answer, and it's always worked for me -- ran another test last night to confirm. Just a single boundary specified in the request header, and then a multi-part message where each part is preceded by the boundary -- the first part contains the JSON body and each subsequent part contains the bytes for a document. – Kim Brandl Dec 11 '13 at 14:31
  • Kim Brandl Thanks for the great help finally after one week of trying and error I have my code working successfully. Also thanks to @Ergin this is the new thread based in the previously I posted remember and yours advices were very helpfull too. – dhernandez Dec 11 '13 at 14:36