1

I have been trying to convert a working POST CURL request into Node JS format that i can automate. Im reaching a wall with converting it and hoping someone can help.

Here is the curl:

curl -POST https://api-xxxxxxxx/add 
-H "Authorization: Bearer xxxxxxx"
-H "Content-Type: multipart/mixed" 
-F 'metadata={ "domain_id": 11661, "container_id": 18569512, "name": "TestFile", "size": "1072902", "originalfilename" : "xxx-d6", "mime": "x-html-package",
"attributes":"main_html_file_path=index.html\nduration=10000" }; type=application/json' -F "file=@xxx-d6.x-html-package"

Im using request-promise module to make this request but i might be making a mistake converting it.


let step1Options = {
    method: 'POST',
    uri: 'https://api-xxx/add',
    form: {
        metadata: {
            domain_id: domainID, 
            container_id: 1856951, 
            name: "TestFileNodeJS", 
            size: "1072902", 
            originalfilename : "xxx-d6", 
            mime: "x-html-package",
            attributes:"main_html_file_path=index.html\nduration=10000"
        },
        file: fs.createReadStream("xxx.x-html-package") 
    },
    headers: {
        "content-type": "multipart/mixed",
        Authorization: "Bearer  " + authID
    }
};

rp(step1Options)
    .then(function (body) {
        console.log("success")
        console.log(body)
    })
    .catch(function (err) {
        console.log("Error: ", err)
        // POST failed...
    });

The error im getting:

  body:
      '{"error":"Unexpected Content-Type header: application/x-www-form-urlencoded. Expecting: multipart/mixed; boundary=<boundary>.","status":"error"}' } }

As far as i know, im changing the Content-Type but still thinks im not. Reading a bit of the documentation of Request-Promise, i dont believe multipart/mixed is a supported? Though i could be wrong.

Does anyone have an idea on how i can get this working or suggest alternatives?

Ben Hedges
  • 23
  • 4

0 Answers0