Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GasFreshdesk OO API Class example #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

GasFreshdesk OO API Class example #22

wants to merge 4 commits into from

Conversation

huan
Copy link
Contributor

@huan huan commented Dec 17, 2015

for issue #21

OO Freshdesk API Class Example.

@huan
Copy link
Contributor Author

huan commented Dec 17, 2015

get rid of clear secret key from source code. get key from ScriptProperties.

@prasadmunna
Copy link

Can you please add ticket reply with attachment for fresh desk PHP API sample code.

@huan
Copy link
Contributor Author

huan commented Jan 12, 2016

@prasadmunna I upgraded my GasFreshdesk library to use the lastest Freshdesk v2 API now, which could use Ticket.reply():

ticket.reply({
  body: 'Hi tom, Still Angry'
  , cc_emails: '[email protected]' 
})

if you could switch from php to javascript, you can try this lib. sorry for I'm not planing write php code, because I only use javascript under google apps script env now.

You could have a look here: GasFreshdesk

@prasadmunna
Copy link

Hi Zixia,
Thanks for your reply, but i am using php library for reply on ticket like this
$ticket_id =68;
$payload = array(
'helpdesk_note[body]' => $postData['message'],
'helpdesk_note[private]' => 'false',
'helpdesk_note[user_id]' => $postData['requester_id']
);
$url = "$fd_domain/helpdesk/tickets/$ticket_id/conversations/note.json";
// $url = "$fd_domain//helpdesk/tickets/$ticket_id/conversations/note.json";
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_USERPWD, "$token:X");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$server_output = curl_exec ($ch);

@huan
Copy link
Contributor Author

huan commented Jan 15, 2016

I'm loving with this in google apps script:

var MyFreshdesk = new Freshdesk('https://DOMAIN.freshdesk.com', 'KEY')

var ticket = new MyFreshdesk.Ticket({
  description:'A description'
  , subject: 'A subject'
  , email: '[email protected]'
})

ticket.assign(9000658396)
ticket.note({
  body: 'Hi tom, Still Angry'
  , private: true
})
ticket.reply({
  body: 'Hi tom, Still Angry'
  , cc_emails: ['[email protected]']
})
ticket.setPriority(2)
ticket.setStatus(2)

ticket.del()
ticket.restore()

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

@big-chris
Copy link

Hi
Thanks very much for your great code. It's saved me a lot of time.

I'm trying to extend it slightly to set custom ticket fields but its failing with an error and I wonder if you could help? Here's what I've done:

I've added your code to a second file in my project and have added the following:

this.setCustomField = setTicketCustomField


      function setTicketCustomField(customFields) {
        // v1: var retVal = http.put('/helpdesk/tickets/' + getTicketId() + '.json', {
        var retVal = http.put('/api/v2/tickets/' + getTicketId(), {
          custom_fields: customFields
        })

        if (retVal) {
          reloadTicket(getTicketId())
          return this
        }

        throw Error('set custom field fail')          
      } 

I then call this by creating the ticket then calling

var thisCustomFields = '"planned_task_43200":"No"';
  ticket.setCustomField(thisCustomFields);

I then get this error
_Error: Freshdesk API v2 failed when calling endpoint[https://xxxxx.freshdesk.com/api/v2/tickets/3651], options[{"muteHttpExceptions":true,"headers":{"Authorization":"Basic d1hmY09jMWdXUEJHT3c1U2JiOlg="},"method":"put","contentType":"application/json","payload":{"custom_fields":""planned_task_43200":"No""}}], description[Validation failed] with error: (code[datatype_mismatch], field[custom_fields], message[Should be a key/value pair]) (line 904, file "gas-freshdesk-lib")

Any thoughts?

@huan
Copy link
Contributor Author

huan commented Feb 22, 2016

@big-chris glad to hear that gas-freshdesk could help you.

can you fork and commit your changes in github? then there's more easy for me to check the code in details for you.

BTW: you should use custom fields like this, I believe it can help you to fix this bug:

var thisCustomFields = { planned_task_43200: "No" }
ticket.setCustomField(thisCustomFields)

@big-chris
Copy link

@zixia thanks a lot for replying.

Sorry I'm pretty new to coding and github so I dont know how to fork and commit changes. I've attached the two files in my project so you can see what I've done.

I tried the suggestion you made about how to use custom fields, but I got a new error message -

Error: Freshdesk API v2 failed when calling endpoint[https://xxxxxx.freshdesk.com/api/v2/tickets/3673], options[{"muteHttpExceptions":true,"headers":{"Authorization":"Basic d1hmY09jMWdXUEJHT3c1U2JiOlg="},"method":"put","contentType":"application/json","payload":{"custom_fields":{"planned_task_43200":"No"}}}], description[Validation failed] with error: (code[invalid_field], field[planned_task_43200], message[Unexpected/invalid field in request]) (line 904, file "gas-freshdesk-lib")

code.gs.txt
gas-freshdesk-lib.gs.txt

@huan
Copy link
Contributor Author

huan commented Feb 23, 2016

@big-chris so there's lots of details of your freshdesk settings.

I recommand you to contact the support of freshdesk: https://support.freshdesk.com/

I created some tickets over there, and they replied quite fast.

@philnatusch
Copy link

@big-chris - probably a bit late for you now as you will have found a way forward, but if you change:
custom_field: customFields
to:
custom_fields: customFields
. . . . it should will work.

@zixia - thanks for this code - saved me so much time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants