# API Error when sending notifcation to phone- call service

**URL:** https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028
**Category:** General
**Tags:** home-assistant
**Created:** [26 February 2022 16:28 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028 "2022-02-26T16:28:06Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Anto79-ops](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anto79-ops/32/56769_2.png) [@Anto79-ops](https://discourse.nodered.org/u/Anto79-ops)
#### Post date: [26 February 2022 16:28 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028/1 "2022-02-26T16:28:06Z")

</div>

Hi!

I have a notification system that notifies me via google assistant speakers when particulate matter (PM) is above a certain threshold. Works well sending the notification to my speakers BUT I als would like for it to be sent as a message on my cell phone (with the companion app), but keep getting an API error when a notification is sent. Please see flow below, along with call service node setup.

 ![API_error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/3/33e0c4e55b781fa93cc4a26aad30597bf9fa6041.jpeg)

Please let me know if you require more informatoin here.

---

<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: [26 February 2022 17:33 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028/2 "2022-02-26T17:33:40Z")

</div>

I do not use HA, you might get a better answer on the HA forum.

But you would need to send the service some data, at least a title and message.  
Try pasting this in where it says data

```auto
{
"title": "A Title",
"message": "A Message"
}

```

If that works, then you can feed a payload into the node and set `data` to msg.payload, or what ever properties you want to use.

> **[Introduction | Home Assistant Companion Docs](https://companion.home-assistant.io/docs/notifications/notifications-basic/)**
>
> The mobileapp notify platform accepts the standard title, message and target parameters used by the notify platform. The mobile\\app notify platform supports targets as services. As long as you granted notifications permissions during setup, you will...

---

<div class="post-metadata">

### Author: ![Anto79-ops](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anto79-ops/32/56769_2.png) [@Anto79-ops](https://discourse.nodered.org/u/Anto79-ops)
#### Post date: [26 February 2022 20:48 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028/3 "2022-02-26T20:48:21Z")

</div>

@E1cid thanks very much! By placing the json text in the data box, and injecting time stamp, it works i get the message I set to my phone app.

How do I now feed the existing payload into the node and set `data` to msg.payload?

Here is the function node before the call node

 ![API_error_2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd2c75ab2170bc7e1becb199abb00a85f4ee0237.jpeg)

---

<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: [26 February 2022 20:55 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028/4 "2022-02-26T20:55:27Z")

</div>

I can not work with text in an image,  
but your function node would be something like this

```auto
msg.payload = {
"title": msg.topic,
"message": msg.some_property_name + " " + msg.some_other_property
};
return msg;

```

Then in `data` you would select `msg` and type in `payload`.

---

<div class="post-metadata">

### Author: ![Anto79-ops](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anto79-ops/32/56769_2.png) [@Anto79-ops](https://discourse.nodered.org/u/Anto79-ops)
#### Post date: [26 February 2022 21:03 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028/5 "2022-02-26T21:03:05Z")

</div>

> [@E1cid](#):
>
> msg.payload,

thanks very much! The function node is as you wrote it, and then I changed the call service node this below

 ![API_error_3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/e/7ec05f747eb15f7d43042b40cf81caad478a39cc.jpeg)

I was not able to find "msg" so i just wrote what what shown in the photo.

---

<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: [26 February 2022 21:04 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028/6 "2022-02-26T21:04:52Z")

</div>

You have not selected msg.  
where it says {} click the chevron to the left, select msg. Then type payload.

You will need to add your own properties to the function, the one's i put there are dummy ones to show you how to construct your own. As i said images do not help me help you you need to pastes code.

---

<div class="post-metadata">

### Author: ![Anto79-ops](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anto79-ops/32/56769_2.png) [@Anto79-ops](https://discourse.nodered.org/u/Anto79-ops)
#### Post date: [26 February 2022 21:20 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028/7 "2022-02-26T21:20:13Z")

</div>

I don't have msg when select the chevron to the left. please see here:

 ![del2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5f81764320567763c770928e701f36b151e7dcd3.jpeg)

here is my function node in code

```auto
msg.payload = msg.topic + " Particulate Matter levels are at " + msg.PM25EOut_reading + " ug/m3";
return msg;

```

---

<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: [26 February 2022 21:36 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028/8 "2022-02-26T21:36:56Z")

</div>

Then pick j expression and type payload.

You have to then set the function as i showed

```auto
msg.payload = {
"title": "some_title",
"message": msg.topic + " Particulate Matter levels are at " + msg.PM25EOut_reading + " ug/m3";
return msg;
};
return msg;

```

[edit]

Or you can select J expression (JSONata) and enter

```auto
{
"title": "A Title",
"message": $$.topic & " Particulate Matter levels are at " & $$.PM25EOut_reading & " ug/m3"
}

```

And not use the function node at all.

---

<div class="post-metadata">

### Author: ![Anto79-ops](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anto79-ops/32/56769_2.png) [@Anto79-ops](https://discourse.nodered.org/u/Anto79-ops)
#### Post date: [26 February 2022 21:51 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028/9 "2022-02-26T21:51:31Z")

</div>

@E1cid thanks for your help !!

---

<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: [12 March 2022 21:52 UTC](https://discourse.nodered.org/t/api-error-when-sending-notifcation-to-phone-call-service/59028/10 "2022-03-12T21:52:18Z")

</div>

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