# UI scheduler node for different json payloads on HTTP requests

**URL:** <https://discourse.nodered.org/t/ui-scheduler-node-for-different-json-payloads-on-http-requests/50617>\
**Category:** Dashboard\
**Created:** [4 September 2021 18:23 UTC](https://discourse.nodered.org/t/ui-scheduler-node-for-different-json-payloads-on-http-requests/50617 "2021-09-04T18:23:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbartling](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bbartling](https://discourse.nodered.org/u/bbartling)\
**Post date:** [4 September 2021 18:23 UTC](https://discourse.nodered.org/t/ui-scheduler-node-for-different-json-payloads-on-http-requests/50617/1 "2021-09-04T18:23:47Z")

</div>

Can someone give me a tip on how to incorporate using the UI scheduler node to send out different different JSON payloads that get rolled into the body of an HTTP GET requests?

The equipment that I am scheduling through ui scheduler handles rest API.

For example when UI scheduler node is `True` from the schedule or the slider I need this JSON payload to start a motor:

```auto
{
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "100",
    "priority": "11"
}

```

When UI scheduler node is `False` from the schedule or the slider, with a slightly different `value`:

```auto
{
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "50",
    "priority": "11"
}

```

The slider from the ui called `MyDevice` works fine either `on` or `off`. I have this add json function where the `MyDevice` values from `on` or `off` come through in the `msg.payload` in Boolean True or False.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/11fff570b6f63ec14decfbe82cef5d357fc37c4e.png)

This is where I am stuck, on the ON or OFF function any tips greatly appreciated, Im still learning javascript.

```auto
var payload = msg.payload

if (payload==True){
    
    // JSON PAYLOAD FOR MOTOR ON
    
    msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "100",
    "priority": "11"
    }
}

if (payload==False){

    // JSON PAYLOAD FOR MOTOR OFF
    
    msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "100",
    "priority": "11"
    }

}

return msg;

```

This is the `add json header` function for what its worth can the two functions be combined?

```auto
msg.headers={"content-type": "application/json"};
return msg;

```

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [4 September 2021 21:18 UTC](https://discourse.nodered.org/t/ui-scheduler-node-for-different-json-payloads-on-http-requests/50617/3 "2021-09-04T21:18:58Z")

</div>

> [@bbartling](#):
>
> This is where I am stuck, on the ON or OFF function

As mentioned in another topic... use **t** rue **f** alse not **T** rue **F** alse

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/4114ffd8ed44f4f87e039d43d3bb2f8894f9e527.png)

```auto
var payload = msg.payload

if (payload==true){
    
    // JSON PAYLOAD FOR MOTOR ON
    
    msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "100",
    "priority": "11"
    }
}

if (payload==false){

    // JSON PAYLOAD FOR MOTOR OFF
    
    msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "0",
    "priority": "11"
    }

}

return msg;

```

---

<div class="post-metadata">

**Author:** ![bbartling](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bbartling](https://discourse.nodered.org/u/bbartling)\
**Post date:** [5 September 2021 12:23 UTC](https://discourse.nodered.org/t/ui-scheduler-node-for-different-json-payloads-on-http-requests/50617/4 "2021-09-05T12:23:47Z")

</div>

Thank you!

---

<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:** [5 October 2021 12:23 UTC](https://discourse.nodered.org/t/ui-scheduler-node-for-different-json-payloads-on-http-requests/50617/5 "2021-10-05T12:23:51Z")

</div>

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