chris
chris

Reputation: 971

First cURL request validating GCM api key

Currently trying to build my first android app with a GCM API key which will be used by a piece of marketing software to send push notifications.

Wanted to get some help validating my google cloud message (GCM) API key with a curl request. I've tried using a online curl builder but the results dont match the success or error message im expecting.

The below request has been copied from the push sdk documentation. If it comes back with a 401 error i need to update my GCM project to a FCM project.

curl --header "Authorization: key=AIzaSyBIuNzItgztXS31MYdl0xnszQcAUO7lbOg"
--header Content-Type:"application/json"
https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"ABC\"]}"

I would obviously love to know how to do this myself also.

Thanks in advance.

Upvotes: 2

Views: 1324

Answers (1)

AL.
AL.

Reputation: 37778

As per my comment, you could try sending a simple downstream message using Postman.

  1. Set request type to POST and provide the URL.

    enter image description here

  2. Set the headers:

    • Authorization = =<Server Key> (here, when you're just starting, it is suggested to proceed with using FCM instead of GCM, since a new valid Server Key can only be generated by creating a Firebase Project).
    • Content-Type = application/json

    enter image description here

  3. Set the (JSON payload) body (as raw):

    {
        "registration_ids" : ["ABC"]
    }
    

    enter image description here

  4. Click on Send .

You should receive an InvalidRegistration, a 401, or an Invalid Legacy Server Key... error:

  • InvalidRegistration error means the token(s) are invalid, but the Server Key is valid.
  • 401 means invalid credentials, for this particular request, it's the Server Key.
  • Invalid (legacy) Server-key delivered or Sender is not authorized to perform request. means you attempted to use an old format Server Key (like the one in your post). New Server Key's have more characters. Usual response is like this:

    <HTML>
    <HEAD>
        <TITLE>Invalid (legacy) Server-key delivered or Sender is not authorized to perform request.</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
        <H1>Invalid (legacy) Server-key delivered or Sender is not authorized to perform request.</H1>
        <H2>Error 401</H2>
    </BODY>
    </HTML>
    

Upvotes: 2

Related Questions