Search code examples
javascriptcurlgoogle-cloud-messagingfirebase-cloud-messagingchrome-gcm

Push notification codelab Uncaught SyntaxError: Unexpected identifier in curl request


I am following this tutorial https://developers.google.com/web/fundamentals/getting-started/codelabs/push-notifications/#send_a_request_from_the_command_line_for_fcm_to_push_a_message

And when I do this

curl --header "Authorization: key=AIzaSyCQHb2t8c3N255bH_CVmGych5QcNntFxYg" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"APA91bE4RJ7_9m2eJ_zlg1F90bLjVX8ctVpCBN24ElAXF--4wS_nnxg4LzkbJWeTe-peMN_StmOaQTEoGeCCNZE5Mssux3T-KbfGRVmRWzeQZM8opfUyv7FVjI9iEfETHG3O7i1qkIb-\"]}"

I get Uncaught SyntaxError: Unexpected identifier

But I did everything as in the tutorial. And I put my api key there, my sender id is in the manifest.json as well, and I put the subscription endpoint url there as well. This is the endpoint endpoint: https://android.googleapis.com/gcm/send/cl72SS1zE50:APA91bE4RJ7_9m2eJ_zlg1F…peMN_StmOaQTEoGeCCNZE5Mssux3T-KbfGRVmRWzeQZM8opfUyv7FVjI9iEfETHG3O7i1qkIb-

So why do I get this error, what identifier does it mean?


Solution

  • curl --header etc etc is a shell command. The tutorial you link to says From your terminal, run the cURL command below

    Uncaught SyntaxError: Unexpected identifier is a JavaScript error message. You appear to be trying to enter that code in a JavaScript program (possibly by pasting it into a browser's Developer Tools Console or a Node.JS REPL).

    You need to run the command on a shell (such as Bash or Windows Power Shell) not in a JS program.