Example API Notification Call

Can someone give me an example of a working notification using the API? I've be trying everything I can find but I'm not a coder so probably don't know the right questions to ask. I have the below but don't know how to insert the payload from the example "payload: {“title”:”Arrived home”, “message”:”Jon has arrived home”}" so it will work.

curl -X POST http://192.168.86.64:57000/api/notify/

curl -X POST -d '{"title":"Arrived home", "message":"Jon has arrived home"}' http://192.168.86.64:57000/api/notify/

2 Likes

Thanks! I wouldn’t have guessed that in million years. Now much Home Assistant fun will be had.

Thanks again!

Spoke too soon. Tried in Linux and Windows and got the following: curl: (3) [globbing] unmatched close brace/bracket in column 29

Use curl -g to turn off globbing. You may need to remove the space after -X too

If you are using any quotation marks or special characters in your payload, they may need to be escaped. It also may depend upon which shell you're using.

Tried several variations and this returned the most interesting error:

curl -XPOST -d -g '{"title":"Arrived home", "message":"Jon has arrived home"}' http://192.168.86.64:57000/api/notify/

In Linux terminal:

[1/2]: "title":"Arrived home" -->
--curl--"title":"Arrived home"
curl: (3) URL using bad/illegal format or missing URL

[2/2]: "message":"Jon has arrived home" -->
--curl-- "message":"Jon has arrived home"
curl: (3) URL using bad/illegal format or missing URL

In Windows CMD:

curl: (3) [globbing] unmatched brace in column 2
curl: (3) [globbing] unmatched close brace/bracket in column 29

Reverse the order. The content must follow the -d option.

Edit:
This works for me:
curl -XPOST -H "Content-Type: application/json" -d '{"title":"Arrived home", "message":"Jon has arrived home"}' http://192.168.86.64:57000/api/notify

In windows you have to escape the quotes. This is an example of Blue Iris sending a security alert when there is motion. I feed it cam location and deepstack detection info as %1 and %2

Try this, just delete %1 and %2 and change the ip address and it should give you something to start with

curl --connect-timeout .5 -X POST -H "Content-Type: application/json" -d "{ "title": "Security Alert", "message": "%1 - Motion Detected %2 "}" http://192.168.12.23:57000/api/notify

hang on it is formatting my escape quotes or something

curl --connect-timeout .5 -X POST -H "Content-Type: application/json" -d "{ \"title\": \"Security Alert\", \"message\": \"%1 - Motion Detected %2 \"}" http://192.168.12.23:57000/api/notify

Perfect! I ended up taking out the %1 and %2 but it worked perfectly! This worked identically in both Linux terminal and Windows CMD. I never would have figured out this on my own -- not without some classes anyway.

Thanks!

You are welcome and I wish I was smart enough to figure this out on my own but I stumbled on it by accident while I was googling something else lol.

1 Like

Also I used the connect timeout because I just "blast" all of my devices because I don't have a way to figure out which ones are active and online. If they are not online it was like a 5 sec timeout.
Maybe someone could help us run a command against the channels server and then parse out the devices that are currently online, write them to a var and then run the api commands :slight_smile:

If you’re using Home Assistant, the integration knows which players are active. Seems like a lot of work to parse that out but it would be more elegant.

so, slampman, you ARE a programmer... because Google is how 99% of us learn how to do what we do... :smile:

2 Likes

I knew a guy who had been coding for years and could just hammer it out like he was typing a email or something. Amazing. Breaks my brain just thinking about it. Now he’s retired and travels around doing gigs playing guitar and singing. Imagine that.

Come to think of it, it would be simple to write checking if Channels is active on a device before sending the notification. I use Node-Red but it would be easy to do it as a condition in a native automation in Home Assistant.

1 Like

I’m assuming the answer to this is no, but is there a way to change the behavior of the notifications such as making the notification larger or font size, etc?

Not with iPhone. Unless you do it in the accessibility settings which would change it for everything.