Last active
February 5, 2016 22:29
-
-
Save yoshprogrammer/f79110057d571328f70d to your computer and use it in GitHub Desktop.
Weebly Cloud API - Create User
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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