npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

freshdesk-nodejs

v1.0.0

Published

Simple client for the Freshdesk V2 API

Downloads

31

Readme

Freshdesk-nodejs

WARNING

npm version

This repository and corresponding NPM package are deprecated in favor of freshdesk-api.

Useful links:

  1. NPM package:
    • v2 is preferred: npm install freshdesk-api
    • v1: npm install freshdesk-api@APIv1
  2. GitHub, node-freshdesk-api:

This module is a simple module to integrate Freshdesk with NodeJS, using the latest API from Freshdesk.

Install

$ npm install freshdesk-nodejs

Usage

You will need your API Key and the URL of your support website to configure the module. You can refer to the Freshdesk Documentation for this

var fd = require('freshdesk-nodejs');
var Freshdesk = new fd('https://mydomain.freshdesk.com', 'APIKEY');

Freshdesk.listTickets(function(err, res, body){
    console.log("Here are the tickets", body);
})

Configuration Options

The constructor of the class takes three parameters :

  • url : The base URL of your support portal
  • apikey : The API key to authenticate on your support portal
  • headers : Optional parameters. Those are the headers that will be added to each HTTP request

Functions

Not all functionalities are yet implemented. However you can still access most of them with the get/post/put/del method. Refer to Freshdesk's documentation for more information.

get

Do a GET request against the path parameter. Used by all other methods requiring a GET action, but you can also use it with your own path to access functions not yet implemented.

Freshdesk.get('/api/v2/contacts/2', function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Here is Contact 2 : " + body);
    };
});

post

Do a POST request against the path parameter while sending data. Used by all other methods requiring a POST action, but you can also use it with your own path and data to access API functions not yet implemented.

const myNewContact = {
    "name" : "Customer 1",
    "email" : "[email protected]",
    "other_emails" : ["[email protected]", "[email protected]"]
};
Freshdesk.post('/api/v2/contacts', myNewContact, function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Contact created : " + body);
    };
});

put

Do a PUT request against the path parameter while updating data. Used by all other methods requiring a PUT action, but you can also use it with your own path and data to access API functions not yet implemented.

const newInfoOnContact = {
    "name" : "Customer ACME",
    "job_title" : "IT Guy"
};
Freshdesk.put('/api/v2/contacts/1', newInfoOnContact, function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Contact updated : " + body);
    };
});

del

Do a DELETE request against the path parameter. We used del instead of DELETE because delete is a reserved word. Used by all other methods requiring a DELETE action, but you can also use it with your own path to access API functions not yet implemented.

Freshdesk.del('/api/v2/contacts/1', function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Contact deleted : " + body);
    };
});

createTicket

Create a ticket

const newTicket = {
    "description" : "My printer stopped working",
    "subject" : "Printers are Satan's children",
    "email" : "[email protected]",
    "priority" : 1,
    "status": 2
};
Freshdesk.createTicket(newTicket, function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Ticket created : " + body);
    };
});

listTickets

List current tickets

Freshdesk.listTickets(function(err, res, body){
   if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Tickets : " + body);
    }; 
});

allTickets

List all tickets. This is a hack as Freshdesk does not support listing all tickets. Therefore we are using a filter to list all tickets updated since 01/01/1970 at 00:00.

Freshdesk.allTickets(function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Tickets : " + body);
    };
}); 

listTicketsSince

This method lists all tickets since the provided date parameter. It is also used by the allTickets method.

Freshdesk.listTicketsSince('2016-08-01T00:00:00Z', function(err, res, body){ // Date is a string using ISO8601
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Tickets since August 1st : " + body);
    };
});

getTicket

Returns all information about a ticket

Freshdesk.getTicket(5, function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Ticket with ID 5 : " + body);
    };
});

updateTicket

Returns all information about a ticket

const newTicketInfo = {
    "priority" : 2,
    "status": 2
};
Freshdesk.putTicket(5, newTicketInfo, function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Ticket with ID 5 has been updated : " + body);
    };
});

deleteTicket

Returns all information about a ticket

Freshdesk.deleteTicket(5, function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Ticket with ID 5 has been deleted: " + body);
    };
});

restoreTicket

Restores a delete ticket

Freshdesk.restoreTicket(5, function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Ticket with ID 5 has been restored : " + body);
    };
});

ticketFields

Returns the expected ticket fields

Freshdesk.ticketFields(function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Those are the required ticket fields :\n" + body);
    };
});

addNoteToTicket

Add a note to the ticket bearing id.

const note = "That's some weird black magic";
Freshdesk.addNoteToTicket(5, note, true, function(err, res, body){ // The third parameter is a boolean, which indicates if the note is private or not.
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Note successfully added to ticket 5 :\n" + body);
    };
});

timeSpentOnTicket

Returns the time spent on a ticket

Freshdesk.timeSpentOnTicket(5, function(err,res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("This is the time that has been spent on ticket 5 :\n" + body);
    };
});

createUser

Created a user/contact

const myNewContact = {
    "name" : "Customer 1",
    "email" : "[email protected]",
    "other_emails" : ["[email protected]", "[email protected]"]
};
Freshdesk.createUser(myNewContact, function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Contact created : " + body);
    };
});

listUsers

List all contacts

Freshdesk.listUsers(function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Here are the users :\n" + body);
    };
});

updateUser

Update user bearing id with data

const newInfoOnContact = {
    "name" : "Customer ACME",
    "job_title" : "IT Guy"
};
Freshdesk.updateUser(newInfoOnContact, function(err, res, body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Contact updated : " + body);
    };
});

getUserByEmail

Returns the user using the email

const email = '[email protected]'
Freshdesk.getUserByEmail(email, function(err,res,body){
    if(err){
        console.log(err);
    };
    if(res.statusCode === 200){
        console.log("Here is user using the email : " + body);
    };
})

Contributing

If you want to add features, fix bugs or generally improve freshdesk-nodejs, please open a pull-request.

License

MIT