# Pass URL from fucntion to call service data

**URL:** https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697
**Category:** General
**Created:** [1 October 2023 09:25 UTC](https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697 "2023-10-01T09:25:31Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![timknowlden](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/timknowlden/32/83339_2.png) [@timknowlden](https://discourse.nodered.org/u/timknowlden)
#### Post date: [1 October 2023 09:25 UTC](https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697/1 "2023-10-01T09:25:32Z")

</div>

Help with passing URL into notification

Hi, I am trying to pass a url into an actionable notification that is to take doorbell press as a trigger to check for doubletake if there is a facial match, send the snapshot into a notification or if its unknown to send the latest unknown snapshot from the doorbell. if i check the debug it shows the URL, but when pressing the notification on my phone it doesnt open the image, it instead loads my dashboard.

This is the function node:

```auto
    function toProperCase(str) {
    return str.replace(/\w+/g, function(txt) {
    return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase();
    });
    }
    
    
    // Check if msg.doubletake and its properties exist
    if (msg.payload && msg.payload.attributes && msg.payload.attributes.matches && msg.payload.attributes.matches[0]) {
    var name = msg.payload.attributes.matches[0].name;
    var snapshot = msg.payload.attributes.matches[0].filename;
    
    if (name && snapshot) {
    // Both 'name' and 'image' exist, publish them as is
    msg.name = toProperCase(name); // Use proper case for 'name'
    msg.snapshot = 'https://domain.com/api/storage/matches/' + snapshot;
    } else {
    // At least one of them is missing, publish holding image and name "Someone"
    msg.name = "Someone";
    msg.snapshot = 'https://domain.com/api/storage/matches/' + snapshot; // Remove the extra single quote here
    }
    } else {
    // If msg.doubletake.attributes.matches[0] doesn't exist, publish holding image and name "Someone"
    msg.name = "Someone";
    msg.snapshot = 'https://domain.com/api/storage/latest/front_door.jpg'; // Replace with your desired holding image URI
    
    }
    
    return msg;

```

This is the call service node data:

```auto
    {
        "title": "Front Door",
        "message": "{{name}} Rang the Doorbell at {{mytime}}",
        "data": {
            "ttl": 0,
            "priority": "high",
            "image": "/api/camera_proxy/camera.front_door",
            "channel": "Doorbell-Test",
            "color": "#ff5722",
            "notification_icon": "mdi:doorbell-video",
            "tag": "Doorbell-Test",
            "alert_once": true,
            "actions": [
                {
                    "action": "URI",
                    "title": "Open Reolink App",
                    "uri": "app://com.mcu.reolink"
                },
                {
                    "action": "URI",
                    "title": "Open Snapshot",
                    "uri": "{{snapshot}}"
                }
            ]
        }
    }

```

---

<div class="post-metadata">

### Author: ![timknowlden](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/timknowlden/32/83339_2.png) [@timknowlden](https://discourse.nodered.org/u/timknowlden)
#### Post date: [1 October 2023 09:39 UTC](https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697/2 "2023-10-01T09:39:50Z")

</div>

![Screenshot_20231001_103922_Brave](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/d/4de3887533d7fc0483f3abba486fde14d87558fd.jpeg)

---

<div class="post-metadata">

### Author: ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)
#### Post date: [1 October 2023 13:54 UTC](https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697/3 "2023-10-01T13:54:06Z")

</div>

This looks like you are using Node Red in Home Assistant. Perhaps this link in the HA forum will help you [Call Service -- Notification w/ Image ... Works in HA but not NodeRED - Third party integrations / Node-RED - Home Assistant Community (home-assistant.io)](https://community.home-assistant.io/t/call-service-notification-w-image-works-in-ha-but-not-nodered/428332)

---

<div class="post-metadata">

### Author: ![timknowlden](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/timknowlden/32/83339_2.png) [@timknowlden](https://discourse.nodered.org/u/timknowlden)
#### Post date: [1 October 2023 14:40 UTC](https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697/4 "2023-10-01T14:40:36Z")

</div>

Hi, yes this is home assistant.

If i change the uri in the call service node to be "[domain.com](http://domain.com)" instead of "{{snapshot}}" the link works, but not when passed in from the function node. Even though thr debug shows that snapshot variable populates a working URL.

You can also see the other variables such as {{mytime}} work correctly.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [1 October 2023 14:55 UTC](https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697/5 "2023-10-01T14:55:51Z")

</div>

As msg.snapshot has special url chars, i.e `:/`, so by default, _mustache_ will escape any non-alphanumeric or HTML entities in the values it substitutes. To prevent this, use `{{{snapshot}}}` triple braces.

---

<div class="post-metadata">

### Author: ![timknowlden](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/timknowlden/32/83339_2.png) [@timknowlden](https://discourse.nodered.org/u/timknowlden)
#### Post date: [1 October 2023 15:22 UTC](https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697/6 "2023-10-01T15:22:09Z")

</div>

Ah i had a feeling the 😕 could have effected something, but didnt know you could tripple mustache, great info and I will give it a go soon.

---

<div class="post-metadata">

### Author: ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)
#### Post date: [1 October 2023 15:29 UTC](https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697/7 "2023-10-01T15:29:03Z")

</div>

The solution I referred to you used entities.

---

<div class="post-metadata">

### Author: ![timknowlden](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/timknowlden/32/83339_2.png) [@timknowlden](https://discourse.nodered.org/u/timknowlden)
#### Post date: [1 October 2023 15:45 UTC](https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697/8 "2023-10-01T15:45:11Z")

</div>

Triple mustache did the job, thank you. That was causing me a headache!

---

<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: [15 October 2023 15:45 UTC](https://discourse.nodered.org/t/pass-url-from-fucntion-to-call-service-data/81697/9 "2023-10-15T15:45:48Z")

</div>

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