HTTP POST multipart-form-data via msg.payload

using this node shown below:
image

I want to pass the url using the msg.payload to this node as we do with http request node but in this url is not acceptable via function node or change node.

Any one can suggest the suitable way please

Does that node have built in help on the sidebar?
What does it say?

By the looks of whatever that node is (you didnt provide a link to it in the flows library so I cant check it out) - but it looks to be a fork of the official HTTP Request node so I assume it uses mustache syntax in the UTL too - have you tried entering {{{msg.url}}} or {{{url}}} or {{{payload}}}?

Hi Steve thanks for replying ok let me try with the way you said. this node is used for multipart form data to get form based api to work

this the link I get the node

Code:

[
    {
        "id": "6e4d8c8220a9787e",
        "type": "group",
        "z": "3173ae332a4790bc",
        "style": {
            "stroke": "#999999",
            "stroke-opacity": "1",
            "fill": "none",
            "fill-opacity": "1",
            "label": true,
            "label-position": "nw",
            "color": "#a4a4a4"
        },
        "nodes": [
            "c7c0cf40cc247303",
            "ba5d8d21cb15e087",
            "4aae5351f23fc98e",
            "373f2919823d3ed1"
        ],
        "x": 174,
        "y": 1079,
        "w": 552,
        "h": 82
    },
    {
        "id": "c7c0cf40cc247303",
        "type": "http-send-multipart-formdata",
        "z": "3173ae332a4790bc",
        "g": "6e4d8c8220a9787e",
        "name": "redirect",
        "ret": "obj",
        "headers": [
            {
                "name": "",
                "value": ""
            },
            {
                "name": "",
                "value": ""
            },
            {
                "name": "",
                "value": ""
            }
        ],
        "formdata": [
            {
                "name": "api_key",
                "value": ""
            },
            {
                "name": "",
                "value": ""
            },
            {
                "name": "workflow_id",
                "value": ""
            },
            {
                "name": "userfile_url",
                "value": ""
            },
            {
                "name": "userfile_url",
                "value": ""
            },
            {
                "name": "",
                "value": ""
            },
            {
                "name": "page",
                "value": ""
            },
            {
                "name": "items_per_page",
                "value": ""
            },
            {
                "name": "documents_order",
                "value": ""
            },
            {
                "name": "detailed",
                "value": ""
            },
            {
                "name": "locations",
                "value": ""
            },
            {
                "name": "deleted",
                "value": ""
            },
            {
                "name": "deleted",
                "value": ""
            }
        ],
        "url": "",
        "credentials": {},
        "x": 465,
        "y": 1120,
        "wires": [
            [
                "ba5d8d21cb15e087"
            ]
        ],
        "l": false
    },
    {
        "id": "ba5d8d21cb15e087",
        "type": "debug",
        "z": "3173ae332a4790bc",
        "g": "6e4d8c8220a9787e",
        "name": "debug 435",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 610,
        "y": 1120,
        "wires": []
    },
    {
        "id": "4aae5351f23fc98e",
        "type": "inject",
        "z": "3173ae332a4790bc",
        "g": "6e4d8c8220a9787e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 280,
        "y": 1120,
        "wires": [
            [
                "373f2919823d3ed1"
            ]
        ]
    },
    {
        "id": "373f2919823d3ed1",
        "type": "change",
        "z": "3173ae332a4790bc",
        "g": "6e4d8c8220a9787e",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "url",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "api_key",
                "pt": "msg",
                "to": "7239",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "method",
                "pt": "msg",
                "to": "POST",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 395,
        "y": 1120,
        "wires": [
            [
                "c7c0cf40cc247303"
            ]
        ],
        "l": false
    }
]

I want to fill the values in formdata using change node

tried this it is not working please check whether there is any bug in node

Looking at the nodes src code, it does not support dynamic URL - only fixed as entered on the form...

You have choices...

  1. use the built in http request node.
  2. raise an issue on the git repository & wait for this to be implemented.

built in http request node is not working for the required form based api call if there is way please tell

API Previewer

  • All requests must be https POST
  • All requests must use the body in the POST
  • All requests must use the form-data option
  • For JSON responses include in the header Accept: application/json

this is mandatory for api call and I tried with builtin http request but didnt work so i searched this node

can we work on source code to get dynamic URL also other things are not dynamic in this node

Short Version...

The HTTP Request node can do this.


Long Version...

Why did it not work?

What problems did you encounter?

Did you open a thread on the forum about your problem with HTTP Request node?


HTTP Request node can do this

HTTP Request node can do this

HTTP Request node can do this (set header multipart/form-data)

Fine!

HTTP Request node can do this (set appropriate header)

So use change node AFTER http request to check the status code & act accordingly.

ok I am trying again. How to pass form data fields as we do in http send multipart node
image

Built in help is your friend...

And so are the forum & google...

Here is a working demo...
chrome_ZanXBfvTa0

This is the endpoint simulating a RESTful API (for demo purposes)

Here is proof the endpoint works with an external client
Code_uBn6XKTpuT

Here is the flow (import using `CTRL-I)...

[{"id":"59760c9d.172d94","type":"http in","z":"bdd21bc1feae09d1","name":"","url":"/document","method":"post","upload":true,"swaggerDoc":"","x":320,"y":660,"wires":[["712bae2ef6258e81"]]},{"id":"54f2edb5.62fca4","type":"http response","z":"bdd21bc1feae09d1","name":"","statusCode":"","headers":{},"x":1450,"y":660,"wires":[]},{"id":"c6242caa.8ec63","type":"comment","z":"bdd21bc1feae09d1","name":"Simulate the POST endpoint that expects multipart form data","info":"","x":460,"y":580,"wires":[]},{"id":"82d3e2daa98ea06f","type":"inject","z":"bdd21bc1feae09d1","name":"Good post, accept JSON","props":[{"p":"payload"},{"p":"payload.api_key","v":"SECRET_KEY","vt":"str"},{"p":"payload.document_id","v":"doc123","vt":"str"},{"p":"headers['Accept']","v":"application/json","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":370,"y":100,"wires":[["0ac7237dae33d2e6","d115e97827516b1a"]]},{"id":"194ef3c7288651d5","type":"http request","z":"bdd21bc1feae09d1","name":"Post multipart form data","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://localhost:1881/document","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[{"keyType":"Content-Type","keyValue":"","valueType":"multipart/form-data","valueValue":""}],"x":950,"y":140,"wires":[["c05e1e3cbf72d093"]]},{"id":"3c5189df59054f42","type":"debug","z":"bdd21bc1feae09d1","name":"Answer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1180,"y":220,"wires":[]},{"id":"712bae2ef6258e81","type":"function","z":"bdd21bc1feae09d1","name":"check / process / respond","func":"const key = msg.payload.api_key\nconst docId = msg.payload.document_id\nif (!docId) {\n    throw new Error('document_id is missing')\n}\nif (key != \"SECRET_KEY\") {\n    msg.statusCode = 401 // denied\n    return msg\n}\n\n// ensure document id is \"doc\" followed by 1 \n// or more numbers e.g. doc123\nif (! /doc\\d+/.test(docId)) {\n    msg.statusCode = 400 // bad request\n    return msg\n}\nmsg.req_headers = {data: msg.req.headers}\nmsg.msg_headers = {data: msg.headers}\nmsg.payload = {\n    valid: true,\n    data: {\n        document_id: docId\n    }\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":660,"wires":[["1d901b4b317f8f7c","ecf5d707a79f1eda"]]},{"id":"ecf5d707a79f1eda","type":"debug","z":"bdd21bc1feae09d1","name":"debug 150","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":510,"y":700,"wires":[]},{"id":"d115e97827516b1a","type":"debug","z":"bdd21bc1feae09d1","name":"This is what the payload should look like","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":400,"y":60,"wires":[]},{"id":"0ac7237dae33d2e6","type":"function","z":"bdd21bc1feae09d1","name":"Prepare multipart payload","func":"const formData = msg.payload\n\nmsg.payload = {\n    api_key: {\n        value: formData.api_key || ''\n    },\n    document_id: {\n        value: formData.document_id || ''\n    },\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":140,"wires":[["194ef3c7288651d5"]]},{"id":"693c378330eb2a15","type":"switch","z":"bdd21bc1feae09d1","name":"200 \\n 400 \\n 401 \\n other","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"},{"t":"eq","v":"400","vt":"num"},{"t":"eq","v":"401","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":650,"y":380,"wires":[["d7fc6ee3757cb401"],["5be560bfd667133d"],["a1181219613e6562"],["e811a3191f935841"]]},{"id":"5be560bfd667133d","type":"debug","z":"bdd21bc1feae09d1","name":"Bad Data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"[\t    \"statusCode: \" & statusCode\t    ,\"payload: \" &  payload\t]","targetType":"jsonata","statusVal":"","statusType":"auto","x":860,"y":380,"wires":[]},{"id":"a1181219613e6562","type":"debug","z":"bdd21bc1feae09d1","name":"Wrong API Key","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"[\t    \"statusCode: \" & statusCode\t    ,\"payload: \" &  payload\t]","targetType":"jsonata","statusVal":"","statusType":"auto","x":880,"y":420,"wires":[]},{"id":"e811a3191f935841","type":"debug","z":"bdd21bc1feae09d1","name":"Unknown","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"[\t    \"statusCode: \" & statusCode\t    ,\"payload: \" &  payload\t]","targetType":"jsonata","statusVal":"","statusType":"auto","x":860,"y":460,"wires":[]},{"id":"152455e3bd029bcc","type":"inject","z":"bdd21bc1feae09d1","name":"Bad API KEY","props":[{"p":"payload"},{"p":"payload.api_key","v":"BAD_KEY","vt":"str"},{"p":"payload.document_id","v":"doc123","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":330,"y":200,"wires":[["0ac7237dae33d2e6"]]},{"id":"a915d3517ba8cc25","type":"inject","z":"bdd21bc1feae09d1","name":"bad document ID","props":[{"p":"payload"},{"p":"payload.api_key","v":"SECRET_KEY","vt":"str"},{"p":"payload.document_id","v":"docABC","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":340,"y":240,"wires":[["0ac7237dae33d2e6"]]},{"id":"b6c1a198b53ee540","type":"inject","z":"bdd21bc1feae09d1","name":"bad data","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":320,"y":280,"wires":[["0ac7237dae33d2e6"]]},{"id":"a24465bb8b2b5b52","type":"catch","z":"bdd21bc1feae09d1","name":"","scope":["712bae2ef6258e81","1d901b4b317f8f7c","c7530bbcca12631d","110d532e1e46df8f","f7de9f090d8f6a38","a2ccb3d767345708","6b3b4684e24c2a86"],"uncaught":false,"x":1150,"y":600,"wires":[["bb0ce0682ddf23bd"]]},{"id":"d7fc6ee3757cb401","type":"switch","z":"bdd21bc1feae09d1","name":"JSON? \\n XML?","property":"headers[\"content-type\"]","propertyType":"msg","rules":[{"t":"cont","v":"json","vt":"str"},{"t":"cont","v":"xml","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":880,"y":280,"wires":[["be01b8754060a568"],["d8fab5ec64ea501b"],["25f5bcd5f0cdea0b"]]},{"id":"be01b8754060a568","type":"json","z":"bdd21bc1feae09d1","name":"","property":"payload","action":"","pretty":false,"x":1050,"y":220,"wires":[["3c5189df59054f42"]]},{"id":"d8fab5ec64ea501b","type":"xml","z":"bdd21bc1feae09d1","name":"","property":"payload","attr":"","chr":"","x":1050,"y":280,"wires":[["6d8d5a2b1bd6697a"]]},{"id":"6d8d5a2b1bd6697a","type":"debug","z":"bdd21bc1feae09d1","name":"Answer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1180,"y":280,"wires":[]},{"id":"1d901b4b317f8f7c","type":"switch","z":"bdd21bc1feae09d1","name":"JSON? \\n XML? \\n text","property":"req.headers.accept","propertyType":"msg","rules":[{"t":"cont","v":"json","vt":"str"},{"t":"cont","v":"xml","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":3,"x":780,"y":660,"wires":[["110d532e1e46df8f"],["c7530bbcca12631d"],["f7de9f090d8f6a38"]]},{"id":"c7530bbcca12631d","type":"xml","z":"bdd21bc1feae09d1","name":"","property":"payload","attr":"","chr":"","x":950,"y":680,"wires":[["6b3b4684e24c2a86"]]},{"id":"f7de9f090d8f6a38","type":"json","z":"bdd21bc1feae09d1","name":"","property":"payload","action":"","pretty":false,"x":950,"y":720,"wires":[["a2ccb3d767345708"]]},{"id":"a2ccb3d767345708","type":"change","z":"bdd21bc1feae09d1","name":"set content type json (string)","rules":[{"t":"set","p":"headers[\"content-type\"]","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":720,"wires":[["54f2edb5.62fca4"]]},{"id":"110d532e1e46df8f","type":"change","z":"bdd21bc1feae09d1","name":"set content type json (object)","rules":[{"t":"set","p":"headers[\"content-type\"]","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":640,"wires":[["54f2edb5.62fca4"]]},{"id":"6b3b4684e24c2a86","type":"change","z":"bdd21bc1feae09d1","name":"set content type xml","rules":[{"t":"set","p":"headers[\"content-type\"]","pt":"msg","to":"application/xml","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1140,"y":680,"wires":[["54f2edb5.62fca4"]]},{"id":"593e8c3372094553","type":"inject","z":"bdd21bc1feae09d1","name":"Good post. accept XML","props":[{"p":"payload"},{"p":"payload.api_key","v":"SECRET_KEY","vt":"str"},{"p":"payload.document_id","v":"doc123","vt":"str"},{"p":"headers['Accept']","v":"application/xml","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":360,"y":140,"wires":[["0ac7237dae33d2e6"]]},{"id":"25f5bcd5f0cdea0b","type":"debug","z":"bdd21bc1feae09d1","name":"Answer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1180,"y":340,"wires":[]},{"id":"c05e1e3cbf72d093","type":"link out","z":"bdd21bc1feae09d1","name":"link out 1","mode":"link","links":["6abe1ded39bce6bc"],"x":1095,"y":140,"wires":[]},{"id":"6abe1ded39bce6bc","type":"link in","z":"bdd21bc1feae09d1","name":"link in 1","links":["c05e1e3cbf72d093"],"x":565,"y":380,"wires":[["693c378330eb2a15"]]},{"id":"ab404d496523a798","type":"comment","z":"bdd21bc1feae09d1","name":"HTTP Request with form data ....","info":"","x":750,"y":60,"wires":[]},{"id":"bb0ce0682ddf23bd","type":"change","z":"bdd21bc1feae09d1","name":"status 500","rules":[{"t":"set","p":"statusCode","pt":"msg","to":"500","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":600,"wires":[["54f2edb5.62fca4"]]},{"id":"3da04a7bdbee4a71","type":"comment","z":"bdd21bc1feae09d1","name":"IMPORTANT: You will need to change the URL  ↑ HERE ↑ to match your system","info":"","x":860,"y":180,"wires":[]}]

s
thanks let me try this i will update

can we use change node instead of inject node as url to be varied

form data is filling it is working but same issue of making it dynamic

I have two workflows and need to merge in one
one workflow gives the uploading file urls
other workflow will give new url for redirect
both will merge and make a file to be uploaded at end point

when apikey and workflowid is given the new url is generated
this new url is needed to give another http request with file url
after this the file gets uploaded it is mandatory as it is two step process so need two requests also