2

Wanted to develop Web notification on Firebase Cloud Messaging. I'm using axios for requesting but it seems not to be working. It occurs an error:

Error: Request failed with status code 400

The Code:

 componentDidMount() {
    const notifications = {
      notification: [
        {
          title: "Hola!",
          body: "Hello World",
          icon: "https://xxxx.com/icon.png",
          click_action: `https://example.com/`
        }
      ],
      to: token
     };
    axios
      .post(
        "https://fcm.googleapis.com/fcm/send",
        {
          notifications
        },
        {
          headers: {
            "Content-Type": "application/json",
            Authorization:
              "key=<FCM_SERVER_KEY>"
          }
        }
      )
      .then(response => {
        console.log("response" + response);
      })
      .catch(error => {
        console.log(error);
      });
k10a
  • 947
  • 2
  • 11
  • 30

1 Answers1

1

You need to set the API KEY on the headers of axios.

The API KEY you found on the Console of Firebase Cloud Messaging.

Zarkys Salas
  • 121
  • 1
  • 4