0

Here is my code that I am attempting to set up a firebase call to send a message to a topic. I get a 200 response code back but nothing appears on the FCM console. Am i doing something wrong.

public static void pushFCMNotification() throws Exception{

   String authKey = Constants.AUTH_KEY_FCM; 
   String FMCurl = Constants.API_URL_FCM;
   URL url = new URL(FMCurl);
   HttpURLConnection conn = (HttpURLConnection) url.openConnection();

   conn.setUseCaches(false);
   conn.setDoInput(true);
   conn.setDoOutput(true);

       conn.setRequestMethod("POST");
        conn.setRequestProperty("Authorization","key="+authKey);
        conn.setRequestProperty("Content-Type","application/json");

        JSONObject json = new JSONObject();
        JSONObject info = new JSONObject();
        try {
            info.put("title", "New notification"); // Notification title
            info.put("body", "A new notification has been added to the notice board"); // Notification body
            json.put("notification", info);
            json.put("to", "/topics/notif"); //replace userDeviceIdKey with the unique notification key for the group
        } catch (JSONException e) {
            e.printStackTrace();
        }
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(json.toString());
        wr.flush();
        conn.getInputStream();
    }

Thanks for the help in advance.

KENdi
  • 7,576
  • 2
  • 16
  • 31
Ryan Richard
  • 37
  • 1
  • 8

1 Answers1

1

Messages sent through the REST API don't appear in the console (regardless if it's sent to a token or to a topic).

Usually, if you use the REST API to send to a token, you could view it in the Diagnostics Page. However, messages sent to topics don't appear there as well. (see the Possible duplicate post I linked in the comments section)

AL.
  • 36,815
  • 10
  • 142
  • 281