Skip to content

Instantly share code, notes, and snippets.

@thenickcox
Created September 29, 2016 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thenickcox/9e58b3350adee2aae73d90d33a302888 to your computer and use it in GitHub Desktop.
Save thenickcox/9e58b3350adee2aae73d90d33a302888 to your computer and use it in GitHub Desktop.
const http = require('http');
const querystring = require('querystring');
const data = {
is_admin: true,
default_hourly_rate: 100,
email: 'foo@bar.com',
first_name: 'Nick',
last_name: 'Cox',
created_at: '2016-09-27 18:37:07',
telephone: '206-555-1234',
};
const usersSend = (data) => {
const TenThousandTestEndPoint = 'localhost';
const TenThousandKey = 'RDV3VlAwV1hYdElwSmNUOHRwbkt5bW9XM29LM2hTL1dvUjVNWGRXWnhpT2dDRlZVK0prYUptRWFxUUc4ClJrWHJHa1kvWW9pWXFpcFpPblplQ29ka21taGdtQnZoMDJGcmFDblR6dlpLMlJRPQo=';
const accountowner = data.is_admin;
const billable = data.default_hourly_rate ? true : false;
const billrate = data.default_hourly_rate;
const deleted = data.active ? false : true;
const email = data.email;
const firstname = data.first_name;
const hiredate = data.created_at;
const lastname = data.last_name;
const mobilephone = data.telephone ? data.telephone : ``;
const apiData = querystring.stringify({
"account_owner": accountowner,
"billable": billable,
"billrate": billrate,
//"deleted": deleted,
"email": email,
"first_name": firstname,
"hire_date": hiredate,
"last_name": lastname,
"mobile_phone": mobilephone
});
const opts = {
method: 'POST',
hostname: 'localhost',
port: 3000,
path: '/api/v1/users',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(apiData),
'auth': TenThousandKey
}
};
const req = http.request(opts, (res) => {
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
res.on('error', (e) => {
console.log(e);
});
});
req.write(apiData);
req.end();
}
usersSend(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment