Boundary not found in request - docusignapi

I am getting the error:
An error was found while parsing the multipart request. Boundary terminator '--BOUNDARY--' was not found in the request.
I have tried debugging with Firefox and chrome with same results.
Any help would be greatly appreciated.
Here is the code I am using:
Public Sub configureMultiPartFormDataRequest(ByVal request As HttpWebRequest, _
ByVal xmlBody As String, _
ByVal docName As String)
'Overwrite the default content-type header and set a boundary marker
request.ContentType = "multipart/form-data; boundary=BOUNDARY"
'Start building the multipart request body
Dim requestBodyStart As String = "\r\n\r\n--BOUNDARY\r\n" + _
"Content-Type: application/xml\r\n" + _
"Content-Disposition: form-data\r\n" + _
"\r\n" + _
xmlBody + "\r\n\r\n--BOUNDARY\r\n" + _
"Content-Type: application/pdf\r\n" + _
"Content-Disposition: file; filename=\" + docName + " \ documentId=1\r\n" + _
"\r\n"
Dim requestBodyEnd As String = "\r\n--BOUNDARY--\r\n\r\n"
'Read the contents of provided document into the request stream
Dim fileStream As FileStream = File.OpenRead(docName)
'Write the body of the request
Dim bodyStart() As Byte = System.Text.Encoding.UTF8.GetBytes(requestBodyStart.ToString())
Dim bodyEnd() As Byte = System.Text.Encoding.UTF8.GetBytes(requestBodyEnd.ToString())
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(bodyStart, 0, requestBodyStart.ToString().Length)
'Read the file contents and write them to the request stream. (4096 Byte Blocks)
Dim buf(4096) As Byte
'Dim len As Integer
'While ((len = fileStream.Read(buf, 0, 4096)) > 0)
' dataStream.Write(buf, 0, len)
'End While
Dim bytesRead As Integer
Do
bytesRead = fileStream.Read(buf, 0, buf.Length)
If bytesRead > 0 Then
dataStream.Write(buf, 0, bytesRead)
End If
Loop While bytesRead > 0
dataStream.Write(bodyEnd, 0, requestBodyEnd.ToString().Length)
dataStream.Close()
End Sub
Added 05/09/2014
Here is the actual request text from Fiddler2. It appears that the bodyEnd is being set to "PDF-1.7". I have searched the code for this string without success. Thanks for your help: \r\n\r\n--BOUNDARY\r\nContent-Type: application/xml\r\nContent-Disposition: form-data\r\n\r\nsentDocuSign API - Embedded Signing example1\10.1.11.100\SecureDocs\EnrollmentForms\CrystalReport1.pdf1hmitchell#ata.eduA Adams10010011\r\n\r\n--BOUNDARY\r\nContent-Type: application/pdf\r\nContent-Disposition: file; filename=\XXX\; documentId=1\r\n\r\n%PDF-1.7
David
Thanks for your fix for the BOUNDARY error. I implemented your xml example and now get an error: "The document element did not contain the encoded document, or there is a problem with the encoding."
Here is the request:
--BOUNDARY
Content-Type: application/xml
Content-Disposition: form-data
sentDocuSign API - Embedded Signing example1C:\Hold\myXML.xml1hmitchell#ata.eduA Adams10010011
--BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename=\C:\Hold\myXML.xml \ documentId=1
<nameValue>
<name>canManageAccount</name>
<value>false</value>
</nameValue>
--BOUNDARY--
Thanks for your help!!!

Your code snippet above is missing the calling method so I made my own as shown below to demonstrate how to leverage WebHookapp endpoint to capture what is being sent. So I think you will see that the body is not formatted correctly due to the fact you tried to "escape" the line breaks and carriage return values vs using the chr with the correct value.
Code I added to call you above method
Imports System.IO
Imports System.Net
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim myHTTPRequest As System.Net.HttpWebRequest = WebRequest.Create("http://webhookapp.com/1037371688646089664")
Dim myXML As String = "{SomeXMLorJason: sampleNotFormatedcorrectly}"
Dim myDocName As String = "c:\myXML.xml"
myHTTPRequest.Method = "POST"
configureMultiPartFormDataRequest(myHTTPRequest, myXML, myDocName)
myHTTPRequest.GetResponse()
End Sub
'Your Code goes here ---> from above:
End Class
What is in the file c:\myXML.xml
<nameValue>
<name>canManageAccount</name>
<value>false</value>
</nameValue>
What was sent:
POST /1037371688646089664
content-type multipart/form-data; boundary=BOUNDARY
host webhookapp.com
content-length 439
expect 100-continue
connection Keep-Alive
\r\n\r\n--BOUNDARY\r\nContent-Type: application/xml\r\nContent-Disposition: form-data\r\n\r\n{SomeXMLorJason: sampleNotFormatedcorrectly}\r\n\r\n--BOUNDARY\r\nContent-Type: application/pdf\r\nContent-Disposition: file; filename=\c:\myXML.xml \ documentId=1\r\n\r\n <nameValue>
<name>canManageAccount</name>
<value>false</value>
</nameValue>\r\n--BOUNDARY--\r\n\r\n
What to do to fix your code:
'Start building the multipart request body
' http://www.asciitable.com/
Dim asciLN As String = Chr(10)
Dim asciCR As String = Chr(13)
Dim requestBodyStart As String = asciCR + asciLN + asciCR + asciLN + "--BOUNDARY" + asciCR + asciLN + _
"Content-Type: application/xml" + asciCR + asciLN + _
"Content-Disposition: form-data" + asciCR + asciLN + _
asciCR + asciLN + _
xmlBody + asciCR + asciLN + asciCR + asciLN + "--BOUNDARY" + asciCR + asciLN + _
"Content-Type: application/pdf" + asciCR + asciLN + _
"Content-Disposition: file; filename=\" + docName + " \ documentId=1" + asciCR + asciLN + _
asciCR + asciLN
Dim requestBodyEnd As String = asciCR + asciLN + "--BOUNDARY--" + asciCR + asciLN + asciCR + asciLN
Which will yield:
POST /1037371688646089664
content-type multipart/form-data; boundary=BOUNDARY
host webhookapp.com
content-length 409
expect 100-continue
connection Keep-Alive
--BOUNDARY
Content-Type: application/xml
Content-Disposition: form-data
{SomeXMLorJason: sampleNotFormatedcorrectly}
--BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename=\c:\myXML.xml \ documentId=1
<nameValue>
<name>canManageAccount</name>
<value>false</value>
</nameValue>
--BOUNDARY--
And a general envelope in JSON as Multipart should look like below:
POST http://{server}/restapi/{apiVersion}/accounts/{accountId}/envelopes
X-DocuSign-Authentication: <DocuSignCredentials><Username>{name}</Username><Password>{password}</Password><IntegratorKey>{integrator_key}</IntegratorKey></DocuSignCredentials>
Accept: application/json
Content-Type: multipart/form-data; boundary=AAA
--AAA
Content-Type: application/json
Content-Disposition: form-data
{
"status":"sent",
"emailBlurb":"Test Email Body",
"emailSubject": "Test Email Subject - EnvelopeDefFull",
"documents": [{
"name": "test1.pdf",
"documentId":"1"
"order":"1"
}],
"recipients": {
"signers" : [{
"email": "test#email.com",
"name": "Sally Doe",
"recipientId":"1",
}]
}
}
--AAA
Content-Type: application/pdf
Content-Disposition: file; filename="test1.pdf";documentid=1
<document bytes removed>
--AAA--

Generally speaking your request should look like the following. The only difference is that this example used JSON format instead of XML. Only change you need to make is changing application/json to application/xml for the Content-Type, then change the JSON data to XML format instead.
POST http://{server}/restapi/{apiVersion}/accounts/{accountId}/envelopes
X-DocuSign-Authentication: <DocuSignCredentials><Username>{name}</Username><Password>{password}</Password><IntegratorKey>{integrator_key}</IntegratorKey></DocuSignCredentials>
Accept: application/json
Content-Type: multipart/form-data; boundary=AAA
--AAA
Content-Type: application/json
Content-Disposition: form-data
{
"status":"sent",
"emailBlurb":"Test Email Body",
"emailSubject": "Test Email Subject - EnvelopeDefFull",
"documents": [{
"name": "test1.pdf",
"documentId":"1"
"order":"1"
}],
"recipients": {
"signers" : [{
"email": "test#email.com",
"name": "Sally Doe",
"recipientId":"1",
}]
}
}
--AAA
Content-Type: application/pdf
Content-Disposition: file; filename="test1.pdf";documentid=1
<document bytes removed>
--AAA--
Without seeing the actual request that your code is constructing and sending I can only assume something is wrong with the formatting. Ensure that you have extra newlines (CRLF) where needed and that the document bytes are correctly being written to the request. If you're still stuck you might want to run through a tool such as Fiddler to check the request data...

Related

How can I use Axios to send a request to this API when the example is given using raw text format?

I am trying to use concord technologies cloud fax tool. The goal is to set up incoming and outgoing fax service from a nodejs express server.
This is an example of the 'raw text format' from concord's website. I am not sure how I can convert this to a cal using axios.
POST /api/intake/fax-notify HTTP/1.1
Host: https://nextstep.concord.net
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="FaxMessageId"
bbe58db7-b3f3-461a-9c47-5b803586cc53
Content-Disposition: form-data; name="MessageType"
Inbound
Content-Disposition: form-data; name="AttachmentName"
bbe58db7-b3f3-461a-9c47-5b803586cc53.tif
Content-Disposition: form-data; name="FaxSenderCSID"
Test User (123-555-1212)
Content-Disposition: form-data; name="CallerNumber"
1-123-555-1212
Content-Disposition: form-data; name="CalledNumber"
1-123-555-6789
Content-Disposition: form-data; name="FaxReceivedDateTime"
10/07/2018 10:45:21 AM
Content-Disposition: form-data; name="FaxRecipientTimeZone"
(GMT-06:00) Central Time (US & Canada)
Content-Disposition: form-data; name="FaxPages"
1
Content-Disposition: form-data; name="FaxResolution"
1
Content-Disposition: form-data; name="FaxSpeed"
2
Content-Disposition: form-data; name="AttachmentCount"
1
Content-Disposition: form-data; name="Account"
12345
Content-Disposition: form-data; name="AuthUser"
12345-6789-1212-12345-0001
Content-Disposition: form-data; name="File"; filename="bbe58db7-b3f3-461a-9c47-5b803586cc53.tif"
Content-Type: file
<binary file data>
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Any help would be greatly appreciated, ty.

InvalidParameterValue: Duplicate header 'Content-Transfer-Encoding'

when I am trying to send an attachment with an email I got this error can anyone tell me what am I doing wrong here is the code which i have tried
var payload = `From: 'Amarjeet Singh' <${sender}>
To: ${recipient}
Subject: AWS SES Attachment
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
--NextPart
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
This is the <b>body</b> of the email.
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
Content-Type: application/json; charset=UTF-8;
Content-Disposition: attachment; filename="colors.json"
Content-Transfer-Encoding: base64
${file}
--NextPart--`;
var params = {
RawMessage: {
Data: payload
},
Source: "xyz#gmail.com"
};
If you are using AWS SES your payload has two issues, first your boundary is different, and second just keep in mind the line breaks, your string template should be like this:
var payload = `From: 'Amarjeet Singh' <${sender}>
To: ${recipient}
Subject: AWS SES Attachment
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
This is the <b>body</b> of the email.
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
Content-Type: application/json; charset=UTF-8;
Content-Disposition: attachment; filename="colors.json"
Content-Transfer-Encoding: base64
${file}
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887--`;

INVALID_REQUEST_PARAMETER - filename not found in Content-Disposition header of multipart form

I am attempting to add a document by multipart form to an existing draft envelope via the Docusign REST API endpoint: /envelopes/[envelopeId]/documents/[documentId]
The error message I get is:
The request contained at least one invalid parameter. A filename was not
found in the Content-Disposition header ('filename="filename.ext"
As you can see, there is a filename parameter in the Content-Disposition value. I've tried multiple different edits and adjustments of the Content-Disposition header, but each has failed. Here is what appears to be the correct format that throws the error.
Headers:
Authorization "Bearer [token]"
Accept "application/json"
Content-Type "multipart/form-data; boundary=AAAAAA"
--AAAAAA
Content-Disposition: form-data
Content-Type: application/json
{"fileExtension":"pdf","name":"test file name.pdf","documentId":1,"order":1}
--AAAAAA
Content-Disposition: file; filename="test file name.pdf"; documentId=1
Content-Type: application/pdf
[binary output]
--AAAAAA--
Anyone from Docusign or in general able to see what's wrong or give me a hand? Thanks.
multipart/form-data will not work for the updateEnvelopeDocument api
Instead specify the Content-Type and content-disposition in the Headers. Request body should only contain the file stream.
put /envelopes/[envelopeId]/documents/[documentId]
[Headers]
Content-Type: application/pdf
content-disposition: file; filename="test file name.pdf"; fileExtension=pdf; documentId=1
[Body]
[binary output]
The other option is to use the updateListEnvelopeDocuments api which supports multipart/form-data. You can also choose to update multiple documents in a single api call using this api.
PUT /v2/accounts/{accountId}/envelopes/{envelopeId}/documents
Headers:
Authorization "Bearer [token]"
Accept "application/json"
Content-Type "multipart/form-data; boundary=AAAAAA"
--AAAAAA
Content-Type: application/json
Content-Disposition: form-data
{
"documents": [
{
"documentId": 1,
"fileExtension": "pdf",
"name": "test file name.pdf"
}
]
}
--AAAAAA
Content-Type: application/pdf
Content-Disposition: file; filename="test file name.pdf"; fileExtension=pdf; documentId=1
Content-Transfer-Encoding: stream
[Binary output]
--AAAAAA--

Python 3, using requests with POST but 302 status and strange request payload headers

Trying to use the Python Requests module to post to a form:
using Chrome/inspect/network tab after I search for something is
shows:
Request
URL:https://www.fbo.gov/index?s=opportunity&mode=list&tab=search
Status Code:302 Found
The Request Payload is:
... begin snippet ....
procurement_notice
------WebKitFormBoundary9stOUHDiQLr2yrEB Content-Disposition: form-data; name="dnf_class_values[procurement_notice][notice_id]"
8045295a672345856701e8ff0ab87a4c
------WebKitFormBoundary9stOUHDiQLr2yrEB Content-Disposition: form-data;
name="dnf_class_values[procurement_notice][_so_agent_save_agent]"
------WebKitFormBoundary9stOUHDiQLr2yrEB Content-Disposition: form-data;
name="dnf_class_values[procurement_notice][custom_response_date]"
------WebKitFormBoundary9stOUHDiQLr2yrEB Content-Disposition: form-data;
name="dnf_class_values[procurement_notice][custom_posted_date]"
30
------WebKitFormBoundary9stOUHDiQLr2yrEB Content-Disposition: form-data; name="dnf_class_values[procurement_notice][keywords]"
Colorado
... end snippet ....
The code, I am trying is:
import requests
headers ={'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 GTB7.1 (.NET CLR 3.5.30729)'}
url = 'https://www.fbo.gov/index?s=opportunity&mode=list&tab=search'
search_data={"dnf_class_values[procurement_notice][keywords]":Colorado}
r = requests.post(url, data=search_data, headers=headers)
it doesn't give me the r.content as if I passed in the search term 'Colorado'.
So my question is does the 'Code:302', which is a re-direct, mean they don't accept a POST request and also how do I deal with the 'WebKitFormBoundary' ...'Content-Disposition: form-data...' as it doesn't look like a normal dictionary element I can pass in.

TXT post to DocuSign always gives INVALID_MULTI_PART_REQUEST Boundary terminator not found error

I'm new to this and probably doing something very stupid, but if I carry on like this, I'll be bald!
As a test, I am just trying to send a TXT document for signing to DocuSign via a HTTP Post. I have followed the examples they give (I believe) but what ever I try, I get the same error.
Error:
"INVALID_MULTI_PART_REQUEST",
"message": "An error was found while parsing the multipart request. Boundary terminator '--AAAAA--' was not found in the request.
Ultimately I want to send base64 encoded PDFs but if I cannot even get TXTs to work...
I am using an XML scripting language specific to our in-house application to make the HTTP request, and the process has a diagnostic mode which can dump the request elements out to file to help sort issues: These TXT files are next and I have removed any sensitive data:
REQUESTHEADERS.TXT:
Content-Type: multipart/form-data; boundary=AAAAA
Content-Length: 565
X-DocuSign-Authentication: <DocuSignCredentials> <Username>myemail#myemail.com</Username><Password>mypassword</Password> <IntegratorKey>mykey</IntegratorKey></DocuSignCredentials>
Host: demo.docusign.net
Accept: application/json; charset=UTF-8
Accept-Encoding: identity
User-Agent: Mozilla/3.0 (compatible; Indy Library)
REQUESTDATA.TXT
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-Disposition: form-data
{
"status":"created",
"emailSubject":"Test",
"emailBlurb":"This is a test",
"documents":[
{
"name":"test1.txt",
"documentId":"1",
"order":"1"
}
],
"recipients":{
"signers":[
{
"email":"myemail#myemail.com",
"name":"Fred Blogs",
"recipientId":"1"
}
]
}
}
--AAAAA
Content-Type: text/plain; charset=UTF-8
Content-Disposition: file; filename="test1.txt";documentid=1
Please sign this test document
--AAAAA--
Please, if any one can tell me what is wrong I would be very grateful indeed!
It's the formatting of the call, please take note on where I have line breaks and where I do not.
Request
--AAAAA
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-Disposition: form-data
{
"status":"created",
"emailSubject":"Test",
"emailBlurb":"This is a test",
"documents":[
{
"name":"test1.txt",
"documentId":"1",
"order":"1"
}
],
"recipients":{
"signers":[
{
"email":"myemail#myemail.com",
"name":"Fred Blogs",
"recipientId":"1"
}
]
}
}
--AAAAA
Content-Type: text/plain; charset=UTF-8
Content-Disposition: file; filename="test1.txt";documentid=1
Please sign this test document
--AAAAA--
Response
{
"envelopeId": "{envelopeId}",
"uri": "/envelopes/{envelopeId}",
"statusDateTime": "2015-02-27T18:53:39.5700000Z",
"status": "created"
}

Resources