Chuck Fennimore
Chuck Fennimore

Reputation: 11

DocuSign ColdFusion REST API v2 INVALID_MULTI_PART_REQUEST Boundary terminator '--BOUNDARY--' was not found

I am trying to do a simple request for signature using ColdFusion. I am basing my code on the samples provided, but keep getting this same error. I have tried using validated XML and JSON and get the same error. Here is my code:

<cfset envDef = "<envelopeDefinition xmlns=\'http://www.docusign.com/restapi\'>" & 
"<emailBlurb>This is a test</emailBlurb>" & 
"<emailSubject>API Call for adding signature request to document and sending</emailSubject>" & 
"<status>sent</status>" & 
"<documents>" &
"<document>" & 
"<documentId>1</documentId>" & 
"<name>test.txt</name>" & 
"</document>" & 
"</documents>" &
"<recipients>" & 
"<signers>" & 
"<signer>" & 
"<recipientId>1</recipientId>" & 
"<email>[email protected]</email>" &   
"<name>Charles Fennimore</name>" & 
"<tabs>" & 
"<signHereTabs>" & 
"<signHere>" & 
"<xPosition>100</xPosition>" & 
"<yPosition>100</yPosition>" & 
"<documentId>1</documentId>" & 
"<pageNumber>4</pageNumber>" & 
"</signHere>" &
"</signHereTabs>" & 
"</tabs>" & 
"</signer>" & 
"</signers>" & 
"</recipients>" &  
"</envelopeDefinition>">

<cfset filePath = ExpandPath("../test.txt") />

<!--- read contents of document into the request stream --->
<cffile action="read" file="#filePath#" variable="fileStream" charset="utf-8">

<!--- build the multipart request body --->
<cfset requestBodyStart = "\r\n\r\n--BOUNDARY\r\n" &
            "Content-Type: application/xml\r\n" &
            "Content-Disposition: form-data\r\n" &
            "\r\n" &
            envDef & "\r\n\r\n--BOUNDARY\r\n" & 
            "Content-Type: text/plain\r\n" &
            "Content-Disposition: file; filename='test.txt'; documentId=1; fileExtension='txt'\r\n" &
            "\r\n">

<cfset requestBodyEnd = "\r\n--BOUNDARY--\r\n\r\n">

<cfset requestBody = requestBodyStart & fileStream & requestBodyEnd>

<cfset requestBodyLength = LEN(requestBody)>

<cfhttp url="#theurl#" method="post" multipart="yes">
<cfhttpparam type="header" name="X-DocuSign-Authentication" value="#dsAuthHeader#">
<cfhttpparam type="header" name="Accept" value="application/xml">
<cfhttpparam type="header" name="Content-Type" value="multipart/form-data; boundary=BOUNDARY">
<cfhttpparam type="header" name="Content-Length" value="#requestBodyLength#">
<cfhttpparam type="body" value="#requestBody#">
</cfhttp>

This produces the following requestBody:

\r\n\r\n--BOUNDARY\r\nContent-Type: application/xml\r\nContent-Disposition: form-data\r\n\r\n<envelopeDefinition xmlns=\'http://www.docusign.com/restapi\'><emailBlurb>This comes from Blue</emailBlurb><emailSubject>API Call for adding signature request to document and sending</emailSubject><status>sent</status><documents><document><documentId>1</documentId><name>test.txt</name></document></documents><recipients><signers><signer><recipientId>1</recipientId><email>[email protected]</email><name>Charles Fennimore</name><tabs><signHereTabs><signHere><xPosition>100</xPosition><yPosition>100</yPosition><documentId>1</documentId><pageNumber>4</pageNumber></signHere></signHereTabs></tabs></signer></signers></recipients></envelopeDefinition>\r\n\r\n--BOUNDARY\r\nContent-Type: text/plain\r\nContent-Disposition: file; filename='test.txt'; documentId=1; fileExtension='txt'\r\n\r\nTest file\r\n--BOUNDARY--\r\n\r\n

The file, test.txt contains "Test file".

I am able to get envelope information using the same header information so I know that is not the problem. Any help would be appreciated.

Using cfsavecontent to create the requestBody also did not work:

<cfsavecontent variable="requestBody">

--BOUNDARY
Content-Type: application/xml
Content-Disposition: form-data
#envDef#

--BOUNDARY
Content-Type: text/plain
Content-Disposition: file; filename='test.txt'; documentId=1
#fileStream#

--BOUNDARY--

</cfsavecontent>

And encoding in iso-8859-1 rather than utf-8 also did not work.

Upvotes: 0

Views: 575

Answers (1)

Ergin
Ergin

Reputation: 9356

This might be related to the single quote characters you have around the XML namespace value. When I copied your XML definition into PHP and ran there (I don't have ColdFusion) it complained about improperly formatted xml. I had to change the single quotes to double quotes. Not sure if that's PHP specific but might be worth a try.

So basically, what happens if you change from

<cfset envDef = "<envelopeDefinition xmlns=\'http://www.docusign.com/restapi\'>" &

to this?

<cfset envDef = "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" &

Upvotes: 0

Related Questions