Skip to content

Instantly share code, notes, and snippets.

@tomfa
Created October 8, 2015 08:02
Show Gist options
  • Save tomfa/3de4ed7de47812dee638 to your computer and use it in GitHub Desktop.
Save tomfa/3de4ed7de47812dee638 to your computer and use it in GitHub Desktop.
// nodejs freshdesk implementation
var request = require('request');
var url = "http://yourcompanyname.freshdesk.com"; // Your URL
var apikey = ""; // Your API key
var auth = 'Basic ' + new Buffer(apikey + ':X').toString('base64');
var fresh = {
get: function(link, callback) {
request({
url: url + link,
headers: {
'Authorization' : auth
}
},
callback
);
},
post: function(link, data, callback) {
request.post(
{
url: url + link,
json: data,
headers: {
'Authorization' : auth
}
},
callback
);
},
put: function(link, data, callback) {
request.put(
{
url: url + link,
json: data,
headers: {
'Authorization' : auth
}
},
callback
);
}
};
postContact: function(contact, callback) {
fresh.post('/contacts.json', contact, callback);
},
putContact: function(id, contact, callback) {
fresh.put('/contacts/' + id + '.json', contact, callback);
},
getContacts: function(callback) {
fresh.get('/contacts.json?state=all', callback);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment