Skip to content

Instantly share code, notes, and snippets.

@yoshprogrammer
Last active February 5, 2016 22:35
Show Gist options
  • Save yoshprogrammer/079f57231188a1fecd57 to your computer and use it in GitHub Desktop.
Save yoshprogrammer/079f57231188a1fecd57 to your computer and use it in GitHub Desktop.
Weebly Could API - Create User
app.post('/api/user', function (req, res) {
//LIBS - The libs I used for this call.
//var _ = require('lodash'),
// Curl = require('node-libcurl').Curl,
// express = require('express'),
// app = express();
var body = _.pick(req.body, 'email'),
dataArray = JSON.stringify({
"email": body.email
}),
hashRequest = 'POST' + '\n' + 'user' + '\n' + dataArray,
key = YOURAPIKEY,
apiSecret = YOURAPISECRET,
hash = crypto.createHmac('sha256', apiSecret).update(hashRequest).digest('hex'),
encodedHash = new Buffer(hash).toString('base64'),
curl = new Curl(),
url = 'api.weeblycloud.com/user';
curl.setOpt('URL', url);
curl.setOpt('POSTFIELDS', dataArray);
curl.setOpt('CUSTOMREQUEST', 'POST');
curl.setOpt('HTTPHEADER', [
'Content-type: application/json',
'X-Public-Key: ' + key,
'X-Signed-Request-Hash: ' + encodedHash
]);
curl.setOpt('VERBOSE', true ); //Verbose logging, you'll want to turn this off in production
curl.perform();
curl.on( 'end', function( statusCode, body ) {
body = JSON.parse(body);
this.close();
});
curl.on('error', curl.close.bind( curl ));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment