Sending Push Notifications Using GCM Service

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsSending Push Notifications Using GCM Service
(Created page with "DreamFactory 2.5 includes support for Google Cloud Messaging (GCM) Service. It is implemented as a native service of DreamFactory. Once you create a GCM service in DreamFacto...")
(No difference)

Revision as of 01:54, 1 March 2017

DreamFactory 2.5 includes support for Google Cloud Messaging (GCM) Service. It is implemented as a native service of DreamFactory. Once you create a GCM service in DreamFactory, you can use it as a proper push notification provider for your application.

DreamFactory GCM service supports sending push notification to a single device using its device token. The service can also act as a push notification provider for your application by supporting device registration by your application. Here is an overview of how DreamFactory works as a push notification service provider.

  1. In DreamFactory you create an application for your Android app. This application basically represents your Android app in DreamFactory.
  2. When you create an application in DreamFactory you will get an API Key.
  3. Store this API Key in your Android app.
  4. On your Android app, when your user confirms to receive push notification for the app, you make a request to DreamFactory GCM service providing the API Key and the user's device token.
  5. DreamFactory stores the device token under your API Key.
  6. When it's time to send push notification, you make a request to the DreamFactory GCM service providing your notification message and the API Key.
  7. DreamFactory will send the message to all of your registered devices under that API Key.

Creating a DreamFactory GCM Service

You can create a GCM service from the admin console. Log in to the admin console and select the 'Services' tab. Click on the 'Create' button from the left menu. From the Service Type drop down menu select Notification -> GCM Push Notification. Enter all the service configuration information and save the form to create your service. For more details check DreamFactory/Features/Push_Notification_Services.

API Endpoints

Send push notification to all devices registered for your application

POST https://{url}/api/v2/{gcm-service-name}/push?api_key={your-application-api-key}

Request body:

{
  "message": "string",
  "badge": 0,
  "sound": "string",
  "action-loc-key": "string",
  "loc-key": "string",
  "loc-args": [
    "string"
  ],
  "custom": [
    {}
  ]
}

Note: Only message is required in the body. You can also provide the API Key using the request header X-DreamFactory-Api-Key instead of the api_key query parameter.

Send push notification to a single device

POST https://{url}/api/v2/{gcm-service-name}/push

Request body:

{
  "message": "string",
  "badge": 0,
  "sound": "string",
  "action-loc-key": "string",
  "loc-key": "string",
  "loc-args": [
    "string"
  ],
  "custom": [
    {}
  ],
  "device_token": "string"
}

Note: Only message and device_token is required in the body.

Register device tokens

POST https://{url}/api/v2/{gcm-service-name}/register?api_key={your-application-api-key}

Request body:

{
  "device_token": "string"
}

Note: You can also provide the API Key using the request header X-DreamFactory-Api-Key instead of the api_key query parameter.

Replace existing device token

PUT https://{url}/api/v2/{gcm-service-name}/register?api_key={your-application-api-key}

Request body:

{
  "old_token": "string",
  "new_token": "string"
}

Note: You can also provide the API Key using the request header X-DreamFactory-Api-Key instead of the api_key query parameter.

Delete all device tokens

DELETE https://{url}/api/v2/{gcm-service-name}/register?api_key={your-application-api-key}

Note: You can also provide the API Key using the request header X-DreamFactory-Api-Key instead of the api_key query parameter. Warning: This will delete all device tokens that are registered under your application.

List all registered device tokens

GET https://{url}/api/v2/{gcm-service-name}/register?api_key={your-application-api-key}

Note: You can also provide the API Key using the request header X-DreamFactory-Api-Key instead of the api_key query parameter.