PrfctByDsgn
PrfctByDsgn

Reputation: 1050

Howto send notification from raspberry pi using curl

I have an Android app that is receiving notifications via Firebase Cloud Messaging.

Sending notifications from the Firebase Console works fine but I want to send them from a Raspberry Pi using curl like this (found somewhere on stackoverflow):

curl -X POST --header "Authorization:key=<api key>" --header "Content-Type:application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\" : \"<registration id>\", \"notification\" : {\"body\" : \"Yellow\"} \"priority\" : \"high\"}"

That allways givs me:

<HTML>
<HEAD>
<TITLE>Internal Server Error</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Internal Server Error</H1>
<H2>Error 500</H2>
</BODY>
</HTML>

Does anyone know what the problem might be?

Added: my registration id looks like this (almost):

dxxxxxxxVEs:APA9xxxcL--JnhswC1w8utjxxxxxxxxxxxxxxxxxxxglosvLbvEAwh7sxxxxxxxxxQo3Fq4sn0yqZUN6Hy89IB9mAS3FusBo68UE4l3xDVRHxxxxxxxxxxpANAHWuLgXHqBoDsLsXBj

Upvotes: 0

Views: 1005

Answers (1)

Matt Gaunt
Matt Gaunt

Reputation: 9821

You're missing a comma before priority high.

Can debug this by entering JSON into jsonlint.com

This can then be added to CURL like so:

curl -X POST --header "Authorization:key=<api key>" --header "Content-Type:application/json" https://fcm.googleapis.com/fcm/send -d '{"to": "<registration id>", "notification": {"body": "Yellow"},"priority": "high"}'

NOTE: The single quotes to avoid having to escape the double quotes.

Upvotes: 1

Related Questions