Here is a working demo...

This is the endpoint simulating a RESTful API (for demo purposes)
Here is proof the endpoint works with an external client

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":[]}]
