Node.js
const apid = ''; // put your key here
const secretHex = ''; // put your secret here
var crypto = require('crypto')
var querystring = require('querystring');
var https = require('https');
function invokeRFGAPI(command,callback) {
var time = Math.floor(new Date() / 1000);
var hash = crypto.createHmac('sha1', new Buffer(secretHex,'hex')).update(time + command,'utf8').digest('hex')
var options = {
host: 'survey.saysoforgood.com',
port: '443',
path: '/API?apid='+apid+'&time='+time+'&hash='+hash,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(command)
}
};
var req = https.request(options, (res) => {
var response = '';
res.on('data', (d) => {
response += d;
});
res.on('end', function() {
var parsed = JSON.parse(response);
callback(response);
});
});
req.write(command);
req.end();
}
var command = "{ 'command' : 'test/copy/1' , 'data1' : 'THIS IS A TEST' }";
invokeRFGAPI(command,function(response){
console.log(response);
});