Https POST on trigger function to Firebase

I’m trying no notify firebase topic about any change in one of my collection.

What is wrong?

This is the function :

exports = function() {
context.http.post({
url: "https://fcm.googleapis.com/fcm/send",
headers: {
  "Authorization key" : "AAAAI......",
  "Content-Type" : "application/json",
},
body: {
    "to" : "/topics/messaging",
    "notification" : {
      "body" : "Body of Your Notification",
      "title": "Title of Your Notification"
    },
 },
 encodeBodyAsJSON: true
});
};

This is the error

ran on Thu Jun 17 2021 19:35:07 GMT+0300 (Israel Daylight Time)
took 262.907943ms
error:
uncaught promise rejection: http request: “headers” argument must be a object containing only string keys and string array values

I found the syntax error

exports = function() {
return context.http.post({
"Authoritzation": "AAAAIkn1XHI:APA91bFO_JzltUR0hGjjQ5yTOAEM1t5rMeXcdoTNexJ8q_uIW3TYf3La39Lyc_v7bW4mkc46qFE1M2zHfKK0yg22lEO5aHXaNyBtk8vybsJugMXuV-brCBdzVtvAEMZsD-02-NnzDsTv",
"url" : "https://fcm.googleapis.com/fcm/send",
"headers": {
  "Authorization":["key=AAAAI......"],
  "Content-Type" : ["application/json"],
},
"body": {
    "to" : "/topics/messaging",
    "notification" : {
      "body" : "Body of Your Notification2",
      "title": "Title of Your Notification1"
    },
 },
 encodeBodyAsJSON: true
});
};
1 Like