var Client = require('node-rest-client').Client,
    clientOptions = {
      connection: {
        rejectUnauthorized: false,
        requestCert: true,
      }
    },
    client = new Client(clientOptions),
    tokenArgs = {
      'data': {
        'grant_type':'client_credentials',
        'client_id':'foo',
        'client_secret':'bar',
        'scope':'*'
      },
      headers: {
        'Content-Type':'application/json'
      }
    };

// first get access_token with existing client credentials.
client.post('https://api.fronter.com/oauth/token', tokenArgs, function (data, response) {
   console.log("token for existing client", data);

    var getArgs = {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': data['token_type'] + ' ' + data['access_token']
      }
    },
    postArgs = {
      headers: getArgs['headers'],
      data: {
        'client_secret': 'bar',
        'description': 'A dummy client',
        'scope': 'user'
      }
    };

    client.post('https://api.fronter.com/clients', postArgs, function (data, response) {
      console.log('created new client', JSON.parse(data));
      data = JSON.parse(data);

      tokenArgs['data']['client_id'] = data.client_id;
      tokenArgs['data']['client_secret'] = 'bar';

      client.post('https://api.fronter.com/oauth/token', tokenArgs, function (data, response) {
        console.log("received new token", data);
      }).on('error', function (err) {
        console.log('err: ', err);
      });

    }).on('error', function (err) {
      console.log('err: ', err);
    });

}).on('error', function (err) {
  console.log('err: ', err);
});

@@ -116,12 +116,11 @@
 ed: 
-fals
+tru
 e,%0A 
@@ -200,16 +200,17 @@
 tions),%0A
+%0A
     toke
@@ -214,454 +214,75 @@
 oken
-Args = %7B%0A      'data': %7B%0A        'grant_type':'client_credentials',%0A        'client_id':'foo',%0A        'client_secret':'bar',%0A        'scope':'*'%0A      %7D,%0A      headers: %7B%0A        'Content-Type':'application/json'%0A      %7D%0A    %7D;%0A%0A// first get access_token with existing client credentials.%0Aclient.post('https://api.fronter.com/oauth/token', tokenArgs, function (data, response) %7B%0A   console.log(%22token for existing client%22, data);
+ = process.argv%5B2%5D,%0A    client_secret = process.argv%5B3%5D,
 %0A%0A    
-var getArg
+param
 s = 
@@ -322,16 +322,17 @@
 nt-Type'
+ 
 : 'appli
@@ -372,125 +372,38 @@
 ion'
+ 
 : 
-data%5B'token_type'%5D + ' ' + data%5B'access_
+'Bearer ' + 
 token
-'%5D
 %0A  
-    %7D%0A
     %7D,%0A
-    postArgs = %7B%0A      headers: getArgs%5B'headers'%5D,%0A
     
@@ -439,15 +439,24 @@
 ret'
+ 
 : 
-'bar'
+client_secret
 ,%0A  
@@ -474,16 +474,17 @@
 ription'
+ 
 : 'A dum
@@ -514,15 +514,21 @@
 ope'
+ 
 : 'user
+:name
 '%0A  
@@ -541,20 +541,16 @@
     %7D;%0A%0A
-    
 client.p
@@ -593,14 +593,12 @@
 ', p
-ostArg
+aram
 s, f
@@ -620,28 +620,24 @@
 response) %7B%0A
-    
   console.lo
@@ -642,493 +642,26 @@
 log(
-'created new client', JSON.parse(data));%0A      data = JSON.parse(data);%0A%0A      tokenArgs%5B'data'%5D%5B'client_id'%5D = data.client_id;%0A      tokenArgs%5B'data'%5D%5B'client_secret'%5D = 'bar';%0A%0A      client.post('https://api.fronter.com/oauth/token', tokenArgs, function (data, response) %7B%0A        console.log(%22received new token%22, data);%0A      %7D).on('error', function (err) %7B%0A        console.log('err: ', err);%0A      %7D);%0A%0A    %7D).on('error', function (err) %7B%0A      console.log('err: ', err);%0A    %7D);%0A
+JSON.parse(data));
 %0A%7D).

Use cli parameters for client_secret and token.