0

I am working through the tutorial on setting up Cloud Messaging. I followed the instructions in the video on the page https://firebase.google.com/docs/cloud-messaging/js/client?authuser=0 when I try to send the curl command I get a strange error. I have read the Cloud Messaging quickstart as well as a few other pages trying to solve the error, but to no avail.

The command I entered on the command line is:

curl --header "Authorization: key=AIzaSyCFCmFwwWV53PqV2M-NUZyp6lYSz43tUiQ" --header "Content-Type: application/json" -d '{"to": "di6GZyDevbI:APA91bFhNMiuJaMIE3IQL2NurPCWBhCtzculj5uvx-on121Z0UczJ0FyiiQbaRFvGqNs3bmq084vQ-z-8vF_GZQ5J-QCBrWgp4_saWSwTXytZmScNbPLGRkOQns_QgETStDTmLJwixI1", "notification": { "title": "Hello", "body": "World", "icon": "/firebase_logo.png" }}' https://fcm.googleapis.com/fcm/send

The result is:

curl: (3) Port number ended with 'A'
curl: (6) Could not resolve host: notification
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: title
curl: (6) Could not resolve host: Hello,
curl: (6) Could not resolve host: body
curl: (6) Could not resolve host: World,
curl: (6) Could not resolve host: icon
curl: (3) <url> malformed
curl: (3) [globbing] unmatched close brace/bracket in column 1
JSON_PARSING_ERROR: Unexpected character (') at position 0.
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Inversus
  • 3,125
  • 4
  • 32
  • 37
  • What OS are you using for development? – Doug Stevenson Jun 29 '18 at 20:40
  • @DougStevenson Windows 10. I'm very new to this framework so I might be doing something wrong..? – Inversus Jun 29 '18 at 21:03
  • 1
    I think the way that argument quoting works with the windows command shell is different than unix shells. So if you copied that from somewhere, it was probably assuming you're on linux or mac. – Doug Stevenson Jun 29 '18 at 21:04
  • @DougStevenson in fact that was the issue. I just tried replacing the single quotes with a double quote and escaping the inner quotes and it doesn't fail now. Thanks! – Inversus Jun 29 '18 at 21:07

1 Answers1

0

The issue was with the quotes on the windows command line. After replacing the single quotes with double quotes and escaping the inner quotes it works, like so:

curl -X POST -H "Authorization: key=AAAAATYbVMw:APA91bFAEaRl8bZPgWGNGA7BCP22y_OLIlHevfUjEXEEklDav1sOwcxiFiFin625JsdaWJBAF06-U1Ey9-mhz6f2Es9-ztOeXpco6_AkvIbEO4dbe2LnI_JVw-W7mqOT5KeSn23y4b1h" -H "Content-Type: application/json" -d "{\"to\": \"di6GZyDevbI:APA91bFhNMiuJaMIE3IQL2NurPCWBhCtzculj5uvx-on121Z0UczJ0FyiiQbaRFvGqNs3bmq084vQ-z-8vF_GZQ5J-QCBrWgp4_saWSwTXytZmScNbPLGRkOQns_QgETStDTmLJwixI1\", \"notification\": { \"title\": \"Hello\", \"body\": \"World\", \"icon\": \"/firebase_logo.png\" }}" "https://fcm.googleapis.com/fcm/send"

Produces the expected result:

{"multicast_id":5167616001901538265,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1530306327290339%e609af1cf9fd7ecd"}]}
Inversus
  • 3,125
  • 4
  • 32
  • 37
  • I am also having this issue when doing string interpolation: The following variable `JSON_DATA=\''{"notification": {"title": "'"$TITLE"'", "body": "'"$BODY"'", "sound": "'"${SOUND}"'"}, "to": "'"$DEVICE_ID"'"}'\'` gives me a 'notification: {}' JSON, but then when I do `curl -H "Content-type: application/json" -H "Authorization:key=$FIREBASE_SERVER_KEY" -X POST -d '%s' "$JSON_DATA" https://fcm.googleapis.com/fcm/send` it gives me the `JSON_PARSING_ERROR: Unexpected character (') at position 0.` – dsomel21 Jan 30 '20 at 17:56