Zendesk API

Get help with using AutoHotkey and its commands and hotkeys
MikeyG12
Posts: 25
Joined: 03 May 2018, 14:21

Zendesk API

05 Dec 2019, 00:15

Hi again everybody! You all have been super helpful in the past and I usually try as much as I can to figure out the answer before asking for help but this one seemingly goes over my head. I'm trying to write a simple script to pull information from my company's Zendesk ticketing system to quickly display info without combing through a case. I am an admin and created an API token and I'm trying to use some code that I found https://the-automator.com/example-webservice-api-call-extract-json-binary-data-from-smartsheetshere I figured the code should be the same or similar but everytime I try, all I get as a response is that it couldn't authenticate me. Here's the code so far:

Code: Select all

#Include %A_LineFile%\..\JSON.ahk

case_ID:="<theCaseId>.json"
EndPoint:="https://<myCompanyName>.zendesk.com/api/v2/tickets/" case_ID
;***********API Call******************* 
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET", Endpoint . QueryString)
HTTP.SetCredentials("Authorization", "Basic <superLongToken>) 
HTTP.SetRequestHeader("Accept", "application/json")
HTTP.Send() 

URLDownloadToFile, https://<myCompanyName>.zendesk.com/api/v2/tickets/<theCaseId>.json, zdeskrma.json
FileRead json_str, zdeskrma.json
parsed := JSON.Load(json_str)

parsed_out := Format("
(Join`r`n
Subject: {}
RMA Number: {}
)"
, parsed.subject, parsed.30686198)

stringified := JSON.Dump(parsed,, 4)
stringified := StrReplace(stringified, "`n", "`r`n") ; for display purposes only

ListVars
WinWaitActive ahk_class AutoHotkey
ControlSetText Edit1, [PARSED]`r`n%parsed_out%`r`n`r`n[STRINGIFIED]`r`n%stringified%
WinWaitClose
return
I tried to scrub all the info that might identify my company...hopefully I didn't miss anything. Parsing the json info shouldn't be a problem, it's just accessing the data that seems to be my struggle right now. Not sure if I'm doing something wrong. I've been following https://developer.zendesk.com/rest_api/docs/support/introduction but I don't know what I'm doing wrong.
tmplinshi
Posts: 1560
Joined: 01 Oct 2013, 14:57

Re: Zendesk API

05 Dec 2019, 06:43

It should be:
HTTP.SetRequestHeader("Authorization", "Basic <superLongToken>")
or
HTTP.SetCredentials("<Username>", "<Password>", 0)

And..

Code: Select all

URLDownloadToFile, https://<Username>:<Password>@<myCompanyName>.zendesk.com/api/v2/tickets/<theCaseId>.json, zdeskrma.json
MikeyG12
Posts: 25
Joined: 03 May 2018, 14:21

Re: Zendesk API

05 Dec 2019, 10:40

Thank you so much for your response! I tried both SetRequestHeader and SetCredentials as you suggested and I changed URLDownloadToFile and it's still telling me that it's unable to authenticate me. Double checked the username and password as well as the token, and everything seems right. I feel like it's something super simple I'm missing. :headwall:
tmplinshi
Posts: 1560
Joined: 01 Oct 2013, 14:57

Re: Zendesk API

05 Dec 2019, 11:23

It seems you're using the OAuth access token. Try HTTP.SetRequestHeader("Authorization", "Bearer <superLongToken>")

If you have a working curl command line, it can be very easy translated to AHK code.
MikeyG12
Posts: 25
Joined: 03 May 2018, 14:21

Re: Zendesk API

05 Dec 2019, 13:55

It's funny that you should mention curl as I do have a working curl command line:

curl https://<myCompanyName>.zendesk.com/api/v2/tickets/<theCaseId>.json \-v -u <userName>:<password>

Not sure how to implement this into the script though.
MikeyG12
Posts: 25
Joined: 03 May 2018, 14:21

Re: Zendesk API

05 Dec 2019, 14:04

Ignore me! I figured it out! I used https://www.autohotkey.com/boards/viewtopic.php?t=19390#p93622 as a reference! I was able to get the json info output to a file that I then can read!! Thank you so much!!!!!!! :rainbow: :rainbow: :rainbow:
tmplinshi
Posts: 1560
Joined: 01 Oct 2013, 14:57

Re: Zendesk API

05 Dec 2019, 23:32

Code: Select all

HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET", "https://<myCompanyName>.zendesk.com/api/v2/tickets/<theCaseId>.json")
HTTP.SetCredentials("<userName>", "<password>", 0)
HTTP.Send()

json_str := HTTP.ResponseText

MsgBox % json_str

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, barbaque, Bing [Bot], boiler, c7aesa7r, Chiefkes, Google [Bot], Jrdixon_ and 268 guests