Hi,
I am trying to execute a curl command in node red along the following lines:
curl
-H "Authorization: Bearer {{ state_attr('sensor.geo_accesstoken', 'accessToken') }}"
-H "Accept: application/json"
-H "Content-Type: application/json"
'https://api.geotogether.com/api/userapi/system/smets2-live-data/PUT_YOUR_SYSTEMID_HERE'
From my research I think I can do the following:
Get the Acccess token using an http request and creating a function node that sets a global variable as follows:
flow.set("Bearer_token", "Bearer " + msg.payload.accessToken);
return msg;
This seems to work ok.
Next I need to use the token in the next curl command above (see ‘accessToken’)
I am using another function node to set the message headers as indicated in the curl command above which I have as follows:
msg.headers = {"Authorisation" : flow.get("Bearer_token"),
"Accept" : "application/json",
"Content-Type" : "application/json"
};
return msg;
I am outputting this function node into a http node for the url in the curl statement above, but when a try to execute it is giving a 401 error “status”:401,“error”:“Unauthorized”,“message”:"No message
So it seems I am not providing the credentials in the right way.
Any assistance anyone?
Thanks
Here is the current version of the flows:
[{"id":"4681f3324412992f","type":"function","z":"6a33605ba7e01f9b","name":"","func":"\nmsg.payload = { \"identity\" : \"[email protected]\", \"password\": \"myverystrongpassword\" };\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":680,"wires":[["fcbb22fda0328a82"]]},{"id":"8bb2b9a66d545cf9","type":"inject","z":"6a33605ba7e01f9b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":680,"wires":[["4681f3324412992f"]]},{"id":"39328e20ef862967","type":"debug","z":"6a33605ba7e01f9b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1150,"y":680,"wires":[]},{"id":"fcbb22fda0328a82","type":"http request","z":"6a33605ba7e01f9b","name":"GEO Authentication","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://api.geotogether.com/usersservice/v2/login","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":620,"y":680,"wires":[["cbdd2da7999a355f"]]},{"id":"1929b55b23f4ed11","type":"function","z":"6a33605ba7e01f9b","name":"","func":"flow.set(\"Bearer_token\", \"Bearer \" + msg.payload.accessToken);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1000,"y":680,"wires":[["39328e20ef862967"]]},{"id":"cbdd2da7999a355f","type":"json","z":"6a33605ba7e01f9b","name":"","property":"payload","action":"","pretty":false,"x":830,"y":680,"wires":[["1929b55b23f4ed11"]]},{"id":"ba7d6e2a04a05e9d","type":"http request","z":"6a33605ba7e01f9b","name":"Live Data","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://api.geotogether.com/api/userapi/system/smets2-live-data/MYSYSTEMID","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"credentials":{},"x":880,"y":820,"wires":[["5b2037945f17dd86"]]},{"id":"de13c8b61cfb4979","type":"inject","z":"6a33605ba7e01f9b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":820,"wires":[["52673543d1cba814"]]},{"id":"52673543d1cba814","type":"function","z":"6a33605ba7e01f9b","name":"","func":"msg.headers = {\"Authorisation\" : flow.get(\"Bearer_token\"),\n \"Accept\" : \"application/json\",\n \"Content-Type\" : \"application/json\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":820,"wires":[["1e68e3a1583da98a"]]},{"id":"5b2037945f17dd86","type":"debug","z":"6a33605ba7e01f9b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1090,"y":820,"wires":[]},{"id":"b32b4fbc756118b3","type":"debug","z":"6a33605ba7e01f9b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":900,"wires":[]},{"id":"1e68e3a1583da98a","type":"json","z":"6a33605ba7e01f9b","name":"","property":"payload","action":"","pretty":false,"x":710,"y":820,"wires":[["ba7d6e2a04a05e9d","b32b4fbc756118b3"]]}]