Specific CURL command in HTTP-REQUEST node


I want to implement the following CURL command in a simple HTTP node-red node. How can I do that?

curl -k -d "grant_type=client_credentials" -H "Authorization: Basic Zlp2NXJYRZ4T3dQc1dkM0lzREhhWEdzYTpLZHlTbmFiZl8wQldqR3ozQjYxREcxQ01lUW9p, Content-Type: application/x-www-form-urlencoded" https://eco-counter-tools.com/token

I created a Function node like as follows and then connected with HTTP-Request node:

var key ="key string";
var secret = "secret string";
var concatenated = key+":"+secret;
var hash = (new Buffer(concatenated)).toString('base64');

msg.method ='POST';
msg.url = "https://eco-counter-tools.com/token";
msg.headers = {};
msg.headers['Authorization'] = 'Basic '+hash;
msg.headers['Content-Type'] = 'application/x-www-form-urlencoded';
msg.payload = "grant_type=client_credentials";
return msg;

But I got 403 error (No matching resource found in the API for the given request). What did I do wrong?

The above hash and URL are not the actual ones. I modified them for security reason.

Error 403 is normally "forbidden"

Did you get the token correct?

Try putting node.warn(hash) after var hash = ... and compare the hash to your working curl.

Yes the hash is correct. In fact I hard-coded the hash and tried. But still got the same 403.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.