Sending Push Notifications

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsSending Push Notifications
(Publish to a Topic)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
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.
 
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'''
+
=== Create a Push Service ===
  
 
The first step is to create a push notification service on your DreamFactory instance.   
 
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.   
+
In the admin console, go to the Services tab and click 'Create'.   
 
Set the Service Type to 'AWS SNS'.   
 
Set the Service Type to 'AWS SNS'.   
 
Set the service name to 'sns'.   
 
Set the service name to 'sns'.   
Line 12: Line 12:
 
Click Create Service to save your new service.   
 
Click Create Service to save your new service.   
  
'''Retrieve a List of Topics'''
+
=== 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.
+
You can now use any REST client to access your service using the DreamFactory REST API. See other tutorials for authentication options. The following request retrieves a list of available topics. Replace http://localhost:8080 with the URL for your DreamFactory instance. 'sns' in the URL is the name of your push service.
 
   
 
   
 
<pre>GET http://localhost:8080/api/v2/sns/topic</pre>
 
<pre>GET http://localhost:8080/api/v2/sns/topic</pre>
Line 31: Line 31:
 
}</pre>
 
}</pre>
  
'''Publish to a 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.  
 
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.  
  
<pre>POST http://dreamfactory:8888/api/v2/sns/topic/arn%3Aaws%3Asns%3Aus-east-1%3A642246745556%3Atest_topic
+
<pre>POST http://localhost:8080/api/v2/sns/topic/arn%3Aaws%3Asns%3Aus-east-1%3A642246745556%3Atest_topic
  
 
{
 
{
Line 51: Line 51:
 
</pre>
 
</pre>
  
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.
+
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 [[DreamFactory/Tutorials/Server_Side_Scripting|scripting tutorials]] for an example of how to do that.

Latest revision as of 21:48, 15 July 2016

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. See other tutorials for authentication options. The following request retrieves a list of available topics. Replace http://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 how to do that.