FIXED access ticket comments / messages through api | Community
Skip to main content

FIXED access ticket comments / messages through api

  • March 19, 2024
  • 2 replies
  • 0 views

Marc15

This is a fairly basic question (i believe), but I've been baning my head on this.

im using zenpy to talk to the zendesk api. I get a ticket that consists of multiple email messages between the customer and the support desk.

I am only able to open the description field (initial message).

using curl, I do get the comments:

curl   https://{project}.zendesk.com/api/v2/tickets/10001/comments

gets me the comment data.

 

however: 

from zenpy import Zenpy 
client = Zenpy(**creds)
ticket = client.tickets(id=10001)
print(ticket.comment)

gets me an error:

AttributeError: 'Ticket' object has no attribute 'comment'

EDIT


ok I was being an idiot. the way to access comments is right in the zenpy documentation. 

client.tickets.comments(ticket=10001)

returns a comments object that contains all the data

2 replies

  • March 21, 2024

Hey ChefSlaad! 

Looks like you're using the Ticket object. Which is headed in the right direction however, ticket.comment is a write only field. 

To get the entire ticket comment history, you'll want to look at the Comment object. That's because the actual comments data is stored in a secondary object to the ticket object. Basically just need to do a little bit more digging in the nest.

In the ZenPy docs, we actually have this example below which shows how to retrieve all the comments for a ticket.

Hope this helps! 😊

 


Marc15
  • Author
  • March 21, 2024

Hi Erica,

Thank you. I had found that example after posting the question. I later updated my post with the answer so others could find it if they ever Google the question and run across this post.