0
votes

I am trying to send push notification via firebase:

await admin.messaging().sendAll({
token: 'some token',
data: {val1: '1', val2: '2'},
time_to_live: 300,
});

I am getting next error:

{"message":"Send push notification failed, Invalid JSON payload received. Unknown name "time_to_live" at 'message': Cannot find field.","level":"error"}

1
Hi, can you provide a reference to the exact API method you are using? Is this part of Admin SDK?Iamblichus

1 Answers

1
votes

In firebase for time_to_live the key is ttl, also I use this request body for sending push notifications in android apps:

const body = {
  notification: {
    title: 'xxxx',
    body: "xxxxxxxx"
  },
  data: {
    notification_message: "xxxxxx"
  },
  token: 'xxxxxx',
  android: {
    ttl: 3600,
    notification: { icon: 'xxxxx', color: '#b2b2b2' }
  }
}

await admin.messaging().send(body)

Use ttl key in case of time_to_live.