Search code examples
node.jshttpcurlnode-red

Node-red HTTP POST parameters


Can someone help me translate this working curl command into a node-red POST command?

curl -X POST http://URL -H "Authorization: 123123123" -d "subjectUid=789789789"

Here's my partially working function node which creates the parameters and pushes to a http node:

msg.headers = {};
msg.headers={ 
    'Authorization':  '123123123'
};

msg.payload = {};
msg.payload={ 
    'subjectUid': '789789789'
};

return msg

The auth token is accepted, but the server replies that the subjectUid is not set. What am I doing wrong?


Solution

  • This will be that by default the post message will forward on the JSON representation of the msg.payload object, what you want is the form encoding.

    Try adding the following header:

    msg.headers = {};
    msg.headers={ 
        'Authorization':  '123123123',
        'Content-Type': 'application/x-www-form-urlencoded'
    };
    
    msg.payload = {};
    msg.payload={ 
        'subjectUid': '789789789'
    };
    
    return msg