Sending Push notification
A push notification is the delivery of information to a computing device from an application server where the request for the transaction is initiated by the server rather than by an explicit request from the client. While 'push notification' is most often used to refer to notifications on mobile devices.
Each native mobile application platform (iOS, Android) has its own set of development guidelines and standards, as well as its own OSPNS (Operating System Push Notification Service). Most of these OSPNS allow push notifications to include text, images, app badges, and sounds. The OSPNS routes the notification from the application provider to the application user’s device.
To add push notifications to an application, the application publisher registers with the push notification service of the OS for which they’re developing . Then their OS service provides an API to the app publisher so that the app can communicate with the service. The app publisher then adds the SDK to their application, then uploads the app to the appropriate app store. That is, in order to send push notifications to devices, it is necessary to register your application through the Google and iOS servers. Once your application is configured with the servers (Google / iOS), credentials will be generated. These credentials are the permissions granted to be able to send push notifications to the application configured by the client. The next step is to add our SDK to your app, this will allow you to send push notifications and get device tokens from users' devices once they have downloaded and registered your app. Now, you can send a new push notification message through the notification method.
NOTE
The total number of API Calls (requests) that the user can make to the POST /notification endpoint in a certain time has been limited. That is, in case the user exceeds the limit of requests (messages sent) that can be made in a specific time, he/she will not be able to send another request until the established time is up. Once the time has elapsed, the request counter is reset and the request can be sent to the endpoint again.
In this example, the user can send 2 requests in 300 seconds (5 minutes). When a third request is sent within the 5 minute range, the
HTTP Status Code “429”
will be generated and the following parameter will be displayed from the Response body:"errors": { "reason": Too Many Requests" }
. This code tells you that the user has sent too many requests in a given amount of time. Once the required time has elapsed, the request counter is reset to 2, so the user will be able to send two requests again in 5 minutes.To find out if the user exceeds the limit of required requests and the time he/she needs to wait to send the next request, we recommend consulting the Response Header (additional information about the body of the resource). The parameters presented in the response header are the following:
ratelimit-limit: 2
ratelimit-policy: 2;w= 300
ratelimit-remaining: 1
ratelimit-reset: 5m0s
- RateLimit-Limit: return the number of requests left for the client in the time window
- RateLimit-Remaining: return the remaining quota in the current window
- RateLimit-Reset: return the time remaining in the current window, specified in seconds
- RateLimit-Policy: return the quota policy. The quota policy expression can be found in paragraph 2.1 of the IETF draft. The format is, for example, for 2 requests in 300 seconds.
When you send an Push notification message, the request body contains the following data:
HTTP Request : POST / notification
{
"channel": "PUSH",
"request": {
"platform": "ANDROID",
"to": "fxxxYXf7nfQ:APA91bG2Kzd...",
"title": "Free shipping for a month!",
"message": "body notification.",
"credentialId": "5f1640b0869b170ce8c95825"
},
"callbacks": [
"http://www.mycallback.com?id=123"
]
}
The parameters presented in the request body example when sending the Push message are the following:
Parameter | Required | Description |
---|---|---|
channel | Yes | Specifies the type of delivery channel which the notification message will be sent: In this case, we enter the |
request | Yes | Message content. |
request.platform | Yes | Describing the type of OS which is going to be sent over Push. Values: |
request.title | Yes | Title of the push notification. |
request.to | Yes | Identifier that senders use to target specific devices with a push notification (User Device Token). |
request.message | Yes | The content of the Push message that will be sent to the end user. |
request.credentialId | Yes | Once registered the application of the customer through the Google and iOS servers. Type the credential (Google or iOS) to be able to send push notifications to the application configured by the customer. |
request.data | No | Send extra message information (Key - Value). This message is not visible in the notification. |
request.development | No | Apple provides you test and production credentials to send the message in the test or production phase.
By default, the assigned value is Note: The |
request.callbacks | No | Indicate one or more (separated by comma) webhook URLs to notify about the status of the Push delivery. |
request.externalId | No | Alphanumeric identifier used for reporting purposes. |
request.clientId | No | Unique user identifier that can be used for reporting purposes. This is an identifier you can use to uniquely identify the destination address in your systems. This is similar to the externalId and will be sent back to you if you are requesting callbacks that contain status changes of the messages you send. |
callbacks | No | Indicate one or more (separated by comma) webhook URLs to notify about the status of the message delivery.That is, If you want to receive the status of the message you've sent to your subscribers, you need to specify your endpoint. Your endpoint must have a HTTP POST access method and receive a JSON body. The URL is the external callback where the events of the Push notification will be registered and published. Once a Push is processed, its status will be posted to your callback URL. To view the full list and meaning of each status, please refer to the Push Notification Status section. |
The parameters presented in the response body example when sending the Push notification message are the following:
Parameter | Description |
---|---|
meta | "meta" segment is dedicated to metadata regarding the call itself. |
meta.timestamp | Call’s time mark. Sequence of characters identifying when the message has been sent. |
meta.transactionId | Call’s transaction ID, this will help our teams to locate issues faster if arose. |
meta.explain | Useful message regarding the operation or the call. |
The Messaging API publishes the Push message in the Push notification API queue, for this reason the response generates the “meta” segment.
Updated about 14 hours ago