V8 service monetization

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsV8 service monetization

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.

<source lang="javascript"> var payload = {

   username: platform.session.user.email,
   app_key: event.request.headers['x-dreamfactory-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));

} </source>