I am looking to add a step in Zapier where only the comments of a ticket are looked up.
Zendesk documentation shows the below curl, this works perfectly in Postman and returns all the comments of the specified ticket.
The 'Code by Zapier' function however requires me to enter javascript or python.
I don't know much at all about either, using the Curl converted to Python, I get output_missing Please define output or return early.
I'd like to retrieve everything within the JSON where "type": "Comment", and where "public": false,
curl https://{subdomain}.zendesk.com/api/v2/tickets/{ticket_id}/comments.json \
-H "Content-Type: application/json" -v -u {email_address}:{password}
If anyone can point me in the right direction it would be much appreciated.
Here is the code:
import requests
import json
url = "domain.zendesk.com/api/v2/tickets/1234/comments.json"
payload={}
headers = {
'Content-Type': 'application/json',
'Authorization': 'Basic xxx'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
You'll note in the docs that the response has to be returned from the code, not just printed:
# ... your exist code
return response.json()
As an alternative to using Code by Zapier
, you might try using Webhooks by Zapier
, which will let you easily make this single request to Zendesk. If you check out the "Make Request" action. There's detailed instructions here: https://zapier.com/help/create/code-webhooks/send-webhooks-in-zaps#add-a-webhook-action