Python Push notification workflow rule example

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsPython Push notification workflow rule example
  1. POST /api/v2/db/_table/todo triggers script db._table.todo.post.post_process
  2. This script runs AFTER records are written to the db.


import httplib;

payload = event['request']['payload']; host = event['request']['headers']['host'][0]; headers = {

   'x-dreamfactory-api-key':platform['session']['api_key'],
   'x-dreamfactory-session-token':platform['session']['session_token']
   };
   

connection = httplib.HTTPConnection(host);

if payload['resource'] != "":

   for record in payload['resource']:
       msg = '{"Message":"A new Todo named '+record['name']+' was just created!", "Subject":"New Todo Created"}';
       
       # service name is 'push', push to SNS topic by name
       connection.request('POST', '/api/v2/push/topic/arn:aws:sns:us-east-1:xxxxxxxxxx:new_todo', msg, headers);
       response = connection.getresponse();
       
       # output result to storage/logs/dreamfactory.log
       print response.read();