alex smith
alex smith

Reputation: 550

Firebase send multiple notifications data with one request

I use curl post to send notification to firebase. I use registration_ids to send the same notification to multiple clients. But sometimes the notification title/body for each client is different. is Is it possible to send multiple notifications with different title/bodies with the same request?

In other words is it a good idea to bombard firebase with 100 requests? or can it be done via one single request?

Upvotes: 0

Views: 745

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600100

What you're describing is possible in the versioned (/v1) REST API by sending a so-called HTTP batch request. This type of request essentially includes many HTTP requests into a single requests, which means each message can indeed be different.

From the linked documentation, this is an example of what the request looks like:

--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA

POST /v1/projects/myproject-b5ae1/messages:send
Content-Type: application/json
accept: application/json

{
  "message":{
     "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
     "notification":{
       "title":"FCM Message",
       "body":"This is an FCM notification message!"
     }
  }
}

...

--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA

POST /v1/projects/myproject-b5ae1/messages:send
Content-Type: application/json
accept: application/json

{
  "message":{
     "token":"cR1rjyj4_Kc:APA91bGusqbypSuMdsh7jSNrW4nzsM...",
     "notification":{
       "title":"FCM Message",
       "body":"This is an FCM notification message!"
     }
  }
}
--subrequest_boundary--

And here's how you could send this request with curl if you saved the request in a file called batch_request.txt:

curl --data-binary @batch_request.txt -H 'Content-Type: multipart/mixed; boundary="subrequest_boundary"' https://fcm.googleapis.com/batch

Upvotes: 1

Related Questions