# Re-run different nodes at different times

**URL:** <https://discourse.nodered.org/t/re-run-different-nodes-at-different-times/66693>\
**Category:** General\
**Tags:** http-request, function-node\
**Created:** [20 August 2022 10:56 UTC](https://discourse.nodered.org/t/re-run-different-nodes-at-different-times/66693 "2022-08-20T10:56:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrks1337](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrks1337/32/66505_2.png) [@mrks1337](https://discourse.nodered.org/u/mrks1337)\
**Post date:** [20 August 2022 10:56 UTC](https://discourse.nodered.org/t/re-run-different-nodes-at-different-times/66693/1 "2022-08-20T10:56:36Z")

</div>

Hi!

I have the following Flow created to login with an API and then fetch data from a second endpoint.

```auto
[
    {
        "id": "4d1f98b0.642758",
        "type": "http request",
        "z": "c155aa476d7d3fe2",
        "name": "/login",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://eu5.fusionsolar.huawei.com/thirdData/login",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 490,
        "y": 180,
        "wires": [
            [
                "9e0cdaf0c53abc05"
            ]
        ]
    },
    {
        "id": "62206b38.707924",
        "type": "function",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "func": "msg.headers = {}\nmsg.url = \"https://eu5.fusionsolar.huawei.com/thirdData/login\";\nmsg.headers[\"content-type\"] = \"application/json\"\n\n\nmsg.payload = {\n \"userName\": \"API\",\n \"systemCode\": \"1337\"\n}\n\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 180,
        "wires": [
            [
                "4d1f98b0.642758"
            ]
        ]
    },
    {
        "id": "fda2c97918f48fc3",
        "type": "inject",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 180,
        "y": 180,
        "wires": [
            [
                "62206b38.707924"
            ]
        ]
    },
    {
        "id": "0ce4ec69bf9d8b8a",
        "type": "debug",
        "z": "c155aa476d7d3fe2",
        "name": "debug msg",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1570,
        "y": 180,
        "wires": []
    },
    {
        "id": "9e0cdaf0c53abc05",
        "type": "function",
        "z": "c155aa476d7d3fe2",
        "name": "flow save token",
        "func": "flow.set('token', msg.headers[\"xsrf-token\"]);\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 660,
        "y": 180,
        "wires": [
            [
                "8d4abce006eb56da"
            ]
        ]
    },
    {
        "id": "7a3e4af0ea3ffca9",
        "type": "function",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "func": "msg.headers = {}\nmsg.url = \"https://eu5.fusionsolar.huawei.com/thirdData/getDevRealKpi\";\nmsg.headers[\"content-type\"] = \"application/json\"\nmsg.headers[\"XSRF-TOKEN\"] = flow.get(\"token\");\n\nmsg.payload = {\n \"devIds\": \"123\",\n \"devTypeId\": \"1\"\n}\n\nnode.log(msg.payload);\n\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1020,
        "y": 180,
        "wires": [
            [
                "45bbc3580423f628"
            ]
        ]
    },
    {
        "id": "45bbc3580423f628",
        "type": "http request",
        "z": "c155aa476d7d3fe2",
        "name": "/getDevRealKpi",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://eu5.fusionsolar.huawei.com/thirdData/getDevRealKpi",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 1200,
        "y": 180,
        "wires": [
            [
                "0fdbf21d9218945b"
            ]
        ]
    },
    {
        "id": "f2fa10e69d612fbb",
        "type": "inject",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "token",
        "payloadType": "flow",
        "x": 840,
        "y": 220,
        "wires": [
            [
                "7a3e4af0ea3ffca9"
            ]
        ]
    },
    {
        "id": "8d4abce006eb56da",
        "type": "delay",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 840,
        "y": 180,
        "wires": [
            [
                "7a3e4af0ea3ffca9"
            ]
        ]
    },
    {
        "id": "0fdbf21d9218945b",
        "type": "json",
        "z": "c155aa476d7d3fe2",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 1370,
        "y": 180,
        "wires": [
            [
                "0ce4ec69bf9d8b8a",
                "c91763435a1a9f49"
            ]
        ]
    },
    {
        "id": "c91763435a1a9f49",
        "type": "loxone-control-out",
        "z": "c155aa476d7d3fe2",
        "name": "Miniserver",
        "miniserver": "294f4e359f889cd9",
        "control": "",
        "x": 1530,
        "y": 300,
        "wires": []
    },
    {
        "id": "294f4e359f889cd9",
        "type": "loxone-miniserver",
        "host": "192.168.1.1",
        "port": "80",
        "enctype": "0",
        "active": true,
        "keepalive": "30000"
    }
]

```

 ![Screenshot 2022-08-20 at 12.53.04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/ebd45eca9f053a1249ed309da8ab6b2fe3138d3f.png)

What I dont understand is how I can schedule the `/login` http request every 4 hours but the `getDevRealKpi` should get called every 20 seconds as I need the response as UDP message.

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [20 August 2022 12:16 UTC](https://discourse.nodered.org/t/re-run-different-nodes-at-different-times/66693/2 "2022-08-20T12:16:05Z")

</div>

Split your chain. Save the token from `/login` as a flow variable such as `flow.token` in one chain. Then in the second, call `getDevRealKpi` every 20 seconds but using the value of `flow.token`. You can call flow variables anywhere in the flow with a change node, or a function node like this `flow.get("token", "memoryOnly")`or`flow.get("token", "file")`

Don't forget to set the inject nodes to repeat on an interval so they fire at the right rates.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 October 2022 12:16 UTC](https://discourse.nodered.org/t/re-run-different-nodes-at-different-times/66693/3 "2022-10-19T12:16:06Z")

</div>

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