Utilizing Zapier to Retrieve Comments from Zendesk

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()

hey, maybe ur api permissions are kokay on Zendesk? Check if the API token/credentials configured for Zapier hv sufficient rights to access the comments, especially non-public ones. Also, try adding a return statement in ur function, coz zapier scripts look for specific outputs. hpe this helps! :v:

You might want to look into the format of your authentication. Make sure your email and API token are concatenated correctly and encoded in base64. In your Python code, instead of ‘Basic xxx’, you need to replace ‘xxx’ with the base64-encoded string of your email/token. You can generate it using an online tool if you’re not comfortable doing it in code. Also, consider utilizing Python’s json library to properly parse and filter the response data for the specific entries you need. See if this approach streamlines your integration!