Node service monetization

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsNode service monetization
(Created page with "Count usage of a particular service, saving history in a database table. Each time a GET call is made on an API endpoint, write the transaction details to a 'TransactionHistor...")
 
Line 12: Line 12:
 
      
 
      
 
     console.log(response.statusCode + " " + response.statusMessage);
 
     console.log(response.statusCode + " " + response.statusMessage);
 +
    event.setResponse(JSON.parse(body), response.statusCode, 'applicaton/json');
 
});
 
});
 
</source>
 
</source>

Revision as of 17:14, 7 September 2016

Count usage of a particular service, saving history in a database table. Each time a GET call is made on an API endpoint, write the transaction details to a 'TransactionHistory' table. Record the user name, application API key, and timestamp.

var payload = {
 
    user_name: platform.session.user.email,
    api_key: platform.session.api_key,
    timestamp: (new Date()).toString()
};
 
platform.api.post("db/_table/TransactionHistory", {"resource": [payload]}, '', function(body, response){
 
    console.log(response.statusCode + " " + response.statusMessage);
    event.setResponse(JSON.parse(body), response.statusCode, 'applicaton/json');
});