How to fetch Zendesk ticket comments using Zapier automation

I’m trying to create a Zapier workflow that retrieves comments from a specific Zendesk ticket. The goal is to filter and get only certain comment data.

The Zendesk API documentation provides a working curl command that returns all ticket comments when I test it in Postman. However, when I try to use Zapier’s Code step, I need to write this in Python or JavaScript.

I converted the curl request to Python but I keep getting an error message saying output_missing - Please define output or return early.

What I want to accomplish is extracting JSON data where the comment type equals “Comment” and the public field is set to false.

Here’s my current Python attempt:

import requests
import json

api_url = "mycompany.zendesk.com/api/v2/tickets/5678/comments.json"
request_data = {}
request_headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Basic yyy'
}

api_response = requests.get(api_url, headers=request_headers, data=request_data)
print(api_response.text)

Can someone help me understand what I’m missing to make this work properly in Zapier? Any guidance would be really helpful.

I ran into a similar situation last month when building a Zendesk integration. The other responses covered the main issues, but there’s one more thing that tripped me up initially - make sure you’re handling the API authentication properly in Zapier’s environment. Instead of hardcoding the Basic auth token, consider using Zapier’s input fields to pass your credentials securely. Also, add some error handling to catch API rate limits or authentication failures. Something like checking if api_response.status_code == 200: before processing the JSON response will save you headaches later. One gotcha I discovered is that Zendesk sometimes returns empty comment arrays for certain ticket states, so you might want to add a check for that before filtering. The filtering logic in the previous answer looks solid though - that’s exactly how I implemented mine and it works reliably.

zapier code steps need you to return output dict, not just print. try adding return {'comments': api_response.json()} at the end instead of print statement. that should fix the output_missing error your getting

The issue is that Zapier code steps require a proper output format. You need to define an output variable or use a return statement to pass data to the next step. Also, your API URL is missing the https protocol which will cause connection errors.

Here’s the corrected version:

import requests

api_url = "https://mycompany.zendesk.com/api/v2/tickets/5678/comments.json"
request_headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Basic yyy'
}

api_response = requests.get(api_url, headers=request_headers)
response_data = api_response.json()

# Filter comments as needed
filtered_comments = []
for comment in response_data['comments']:
    if comment.get('type') == 'Comment' and comment.get('public') == False:
        filtered_comments.append(comment)

output = {'filtered_comments': filtered_comments}

The key changes are adding https to the URL, removing the unnecessary data parameter, and properly defining the output variable with your filtered results.