V8 service monetization

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsV8 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...")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
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 username, application key, and timestamp.
+
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.
  
 
<source lang="javascript">
 
<source lang="javascript">
 
var payload = {
 
var payload = {
  
     username: platform.session.user.email,
+
     user_name: platform.session.user.email,
     app_key: event.request.headers['x-dreamfactory-api-key'],
+
     api_key: platform.session.api_key,
 
     timestamp: (new Date()).toString()
 
     timestamp: (new Date()).toString()
 
};
 
};
  
var result = platform.api.post("db/_table/TransactionHistory", {resource: [payload]});
+
var result = platform.api.post("db/_table/TransactionHistory", {"resource": [payload]});
  
 
if (result.status_code !== 200) {
 
if (result.status_code !== 200) {

Latest revision as of 17:15, 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()
};
 
var result = platform.api.post("db/_table/TransactionHistory", {"resource": [payload]});
 
if (result.status_code !== 200) {
 
    throw(JSON.stringify(result.content.error.message));
}