Hello,
I am using Node-red to perform API queries on modems.
The steps are as follows:
1 – Request 1: Initialize the connection with the modem - ***It's OK! ***
2 – Request 2: Retrieve the token then send a second request -- *** I'm already blocking HERE!!! ***
3 – Request 3: Wait for the modem's response to the previous request then send a 3rd request.
4 - Request 4: Wait for the modem's response to request no. 2 then send a 4th request
Blocking point :
I manage to recover my token in the debug, but I don't know how to write it as a variable in my second request
Maybe there is another way to do with tokens on node-red?
Information: This development is made to interrogate several hundreds of modems! so as input I would have a CSV file listing all the IP addresses of the different modems, but that's another story...
Thanks a lot for your help !
Mon Token : msg.payload.result.ubus_rpc_session
msg.payload = [{
"jsonrpc": "2.0", "id": 1, "method": "call", "params":
[
"payload.result.ubus_rpc_session", "uci", "set",
{
"config": "sms_utils", "type": "rule", "match":
{
"action": "reboot",
"enabled": "0"
},
"values":
{
"action": "reboot",
"enabled": "1"
}
Flow :
[{"id":"b56aaab0fb521d56","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"3b67977c.a53c08","type":"debug","z":"b56aaab0fb521d56","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":120,"wires":[]},{"id":"4030c52c.c2c29c","type":"inject","z":"b56aaab0fb521d56","name":"API Teltonika","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":200,"wires":[["31727a2c.05a026"]]},{"id":"64d9243f.b7be7c","type":"http request","z":"b56aaab0fb521d56","name":"HTTP-REQUEST","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[],"x":630,"y":200,"wires":[["3b67977c.a53c08","ef71af4768ff47a3","3c3798b006a49db8","c6fbea8afe59bc01"]]},{"id":"31727a2c.05a026","type":"function","z":"b56aaab0fb521d56","name":"Requete","func":"msg.method = \"POST\"\nmsg.url = \"http://172.24.64.48/ubus\"\nmsg.headers = {}\nmsg.headers[\"content-type\"] = \"application/json\"\n\nmsg.payload = [{\n \"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"call\", \"params\":\n [\n \"00000000000000000000000000000000\", \"session\", \"login\",\n {\n \"username\": \"root\", \"password\": \"XXXXX\"\n }\n ]\n}]\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":200,"wires":[["64d9243f.b7be7c"]]},{"id":"3c3798b006a49db8","type":"debug","z":"b56aaab0fb521d56","name":"Token","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.result.ubus_rpc_session","targetType":"jsonata","statusVal":"","statusType":"auto","x":870,"y":180,"wires":[]},{"id":"ef71af4768ff47a3","type":"debug","z":"b56aaab0fb521d56","name":"msgurl","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"url","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":220,"wires":[]},{"id":"c6fbea8afe59bc01","type":"function","z":"b56aaab0fb521d56","name":"Requete","func":"msg.method = \"POST\"\nmsg.url = msg.url\nmsg.headers = {}\nmsg.headers[\"content-type\"] = \"application/json\"\n\nmsg.payload = [{\n \"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"call\", \"params\":\n [\n \"'payload[0].result[1].ubus_rpc_session'\", \"uci\", \"set\",\n {\n \"config\": \"sms_utils\", \"type\": \"rule\", \"match\":\n {\n \"action\": \"reboot\",\n \"enabled\": \"0\"\n },\n \"values\":\n {\n \"action\": \"reboot\",\n \"enabled\": \"1\"\n }\n }\n ]\n}]\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":360,"wires":[["0a011b68ae900ccb"]]},{"id":"0a011b68ae900ccb","type":"debug","z":"b56aaab0fb521d56","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1000,"y":360,"wires":[]}]