freshworks / fresh-samples

Samples of code created by freshdesk
183 stars 182 forks source link

OO Freshdesk API Class for Google Apps Script #21

Open huan opened 8 years ago

huan commented 8 years ago

I had just wrote a easy to use OO wrapper: gas-freshdesk.

looks like this:

var API_TOKEN = PropertiesService.getScriptProperties().getProperty('FreshDeskApiToken')
var MyFreshdesk = new Freshdesk('https://mikebo.freshdesk.com', API_TOKEN)

var ticket = new MyFreshdesk.Ticket({
  helpdesk_ticket: {
    description:'A description'
    , subject: 'A subject'
    , email: 'you@example.com'
  }
})

ticket.assign(9000658396)
ticket.addNote({
  body: 'Hi tom, Still Angry'
  , private: true
})
ticket.setPriority(2)
ticket.setStatus(2)

ticket.del()
ticket.restore()

Logger.log('ticket #' + ticket.getId() + ' was set!')

hope it could useful and help others for easy start to api freshdesk.

meteormanaged commented 8 years ago

Hey, looks like you posted your API key.

Mike Kozak mkozak@meteormanaged.commailto:mkozak@meteormanaged.com

On Dec 17, 2015, at 7:25 AM, Zhuohuan LI notifications@github.com<mailto:notifications@github.com> wrote:

I had just wrote a easy to use OO wrapper: gas-freshdeskhttps://githubcom/zixia/gas-freshdesk/

looks like this:

var MyFreshdesk = new Freshdesk('https://mikebofreshdeskcom', 'Jrg0FQNzX3tzuHbiFjYQ')

var ticket = new MyFreshdeskTicket({ helpdesk_ticket: { description:'A description' , subject: 'A subject' , email: 'you@examplecom' } })

ticketassign(9000658396) ticketaddNote({ body: 'Hi tom, Still Angry' , private: true }) ticketsetPriority(2) ticketsetStatus(2)

ticketdel() ticketrestore()

Loggerlog('ticket #' + ticketgetId() + ' was set!')

hope it could useful and help others for easy start to api freshdesk

Reply to this email directly or view it on GitHubhttps://github.com/freshdesk/fresh-samples/issues/21.

huan commented 8 years ago

@meteormanaged thanks for noticing me that. it's ok, because that key is from my testing account.

I created that account only for unit testing , and also make others to run the sample code easy.

meteormanaged commented 8 years ago
var API_TOKEN = process.env.API_TOKEN;
var MyFreshdesk = new Freshdesk('https://mikebo.freshdesk.com', API_TOKEN);

i would suggest that it's poor practice to include your token in a script in practice, and better to present it as an environment variable (or though some other mechanism).

huan commented 8 years ago

@meteormanaged

i agree with you. it's a poor practice. this is only for demo and example. (also used by my test cases).

if use a environment variable, it should looks like this (because it's in gas, not nodejs)

var API_TOKEY = PropertiesService.getScriptProperties().getProperty('FreshDeskApiToken')
huan commented 8 years ago

@meteormanaged fixed as you suggest. :]