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

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.

Related

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--`;

How can be parse `multipart/mixed` in node.js?

I see lot of module in node.js like busboy , multer , formidable but they are not able to parse multipart/mixed body.
Example of the request multipart/mixed in node.js
--batchbatch
Content-Type: multipart/mixed; boundary=changeset1
--changeset1
Content-Type: application/http
Content-Transfer-Encoding: binary
POST data HTTP/1.1
Content-Type: application/json
Content-ID: ID1
Content-Length: 10000
{
"Name": "ddd",
"data1": "3",
"data2": "40",
"data3": "OPPT",
"data3":"D1000",
"dat4": "D1000"
}
--changeset1--
--batchbatch
Content-Type: multipart/mixed; boundary=changeset2
--changeset2
Content-Type: application/http
Content-Transfer-Encoding: binary
PATCH data/32451 HTTP/1.1
Content-Type: application/json
Content-ID: ID1
Content-Length: 10000
{
"code": "3"
}
--changeset2--
--batchbatch
Content-Type: multipart/mixed; boundary=changeset3
--changeset3
Content-Type: application/http
Content-Transfer-Encoding: binary
DELETE /data/2345 HTTP/1.1
--changeset3--
--batchbatch--

nodejs multipart/formData Request

I am noobie in multipart/formdata request in node js.
I am crawling a website which does multipart/formdata request.This is how it does :
url : https://example.com
Content-Type: multipart/form-data;boundary=----
formdata :
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="to"
destination#email.com
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="from"
recipient#email.com
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="subject"
subject line
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="text"
This content does not matter.
------------------------------7a9cd2dc11c1--
am using request module of node js for doing that. Help, i need example..

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