I want to implement a step in Zapier that fetches only the comments from a specific ticket in Zendesk. The reusable curl command provided in Zendesk’s documentation successfully retrieves all comments for a given ticket when executed in Postman. However, the ‘Code by Zapier’ option requires either JavaScript or Python for execution. I’m not very familiar with these programming languages, and when I attempt to use the curl command converted to Python, I encounter an error message stating, output_missing - Please define output or return early.
My goal is to extract all JSON entries where “type”: “Comment” and “public”: false. Here is a simple example of the curl command I’m working with:
curl https://{subdomain}.zendesk.com/api/v2/tickets/{ticket_id}/comments.json \
-H "Content-Type: application/json" -v -u {email_address}:{password}
If someone can guide me on how to achieve this, it would be greatly appreciated. Here is my current Python code:
import requests
import json
def fetch_comments():
url = "domain.zendesk.com/api/v2/tickets/1234/comments.json"
headers = {
'Content-Type': 'application/json',
'Authorization': 'Basic xxx'
}
response = requests.get(url, headers=headers)
print(response.text)
fetch_comments()