Skip to content

Instantly share code, notes, and snippets.

@Furzel
Created September 25, 2014 01:26
Show Gist options
  • Save Furzel/d1e4d94c7be572313263 to your computer and use it in GitHub Desktop.
Save Furzel/d1e4d94c7be572313263 to your computer and use it in GitHub Desktop.
Basic Front contact API example
var https = require('https');
var apiKey = '*** YOUR API KEY ***',
companySlug = '*** YOUR COMPANY SLUG ***';
var data = {
name: 'Arthur Dent',
description: 'Earthman',
fields: [
{
source: 'email',
handle: 'arthur@sandwichmaker.com'
}, {
source: 'phone',
handle: '+123456789'
}, {
source: 'twitter',
handle: '@arthurd'
}
],
links: [
{url: 'https://en.wikipedia.org/wiki/Douglas_Adams'},
{url: 'http://xkcd.com/'}
]
};
var dataString = JSON.stringify(data);
var options = {
host: 'webhook.frontapp.com',
path: '/api/1/contacts',
auth: companySlug + ':' + apiKey,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': dataString.length
}
};
var req = https.request(options, function (res) {
if (res.statusCode === 202)
console.log('OK');
else
console.log('ERROR');
});
req.write(dataString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment