Sending Push Notifications

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsSending Push Notifications

DreamFactory has built-in support for sending push notifications via Amazon Simple Notification Service (SNS). You can access other types of push notification services as remote web services.

Create a Push Service

The first step is to create a push notification service on your DreamFactory instance.

In the admin console go to the Services tab and click Create. Set the Service Type to 'AWS SNS'. Set the service name to 'sns'. Set the service label to 'Amazon SNS'. Go to the config tab for the new service and enter the access key, secret key, and region for your AWS account. Click Create Service to save your new service.

Retrieve a List of Topics

You can now use any REST client to access your service using the DreamFactory REST API. For example, the following request retrieves a list of available topics. Replace localhost:8080 with the URL for your DreamFactory instance. 'sns' in the URL is the name of your push service.

GET http://localhost:8080/api/v2/sns/topic

The response is an array of topics.

{
  "resource": [
    {
      "TopicArn": "arn:aws:sns:us-east-1:642246745556:another_topic"
    },
    {
      "TopicArn": "arn:aws:sns:us-east-1:642246745556:test_topic"
    }
  ]
}

Publish to a Topic

To publish to the topic 'arn:aws:sns:us-east-1:642246745556:test_topic' you do an HTTP POST to the push service. The payload contains the content in JSON format.

POST http://localhost:8080/api/v2/sns/topic/arn%3Aaws%3Asns%3Aus-east-1%3A642246745556%3Atest_topic

{
  "Message": "Test Message",
  "Subject": "Test Subject"
}

The response contains the message id for the notification.

{
  "MessageId": "38d76df1-3a2e-5952-bc92-2358fa632ff2"
}

For a detailed list of all available endpoints, see the API Docs in the admin console. Selecting the push service in the API Docs will show you all the available options and also let you try out each call. Push notifications can also be sent from server side scripts. See the scripting tutorials for an example of that.