Issue accessing comments from the tickets using ZAF client and JS | Community
Skip to main content

Issue accessing comments from the tickets using ZAF client and JS

  • December 8, 2024
  • 2 replies
  • 0 views

Akshay11

I am trying to fetch the contents of the comments on a zendesk ticket using ZAF client in js but it keeps giving me “undefined”.

eg code -

```

const ticketData = await client.get(['ticket.status', 'currentUser.name',  'ticket.comments']);

const comments = ticketData['ticket.comments'];

const commentContent=comments[0].body;

```

I also tried fetching the comments using the API - GET /api/v2/tickets/{ticket_id}/comments, and then using .body on one of the comments and still the same issue.

 

When I do a curl i do see the JSON response but when using 

commentContent=comments[0].body I get undefined.

Could you please help me understand how to fetch the contents of the comments?

2 replies

Akshay11
  • Author
  • December 9, 2024

I also tried using `ticket.latest_public_comment`

 

I get the error InvalidPathError: Path 'latest_public_comment' doesn't exist on node 'ticket'

 


Tipene
  • December 10, 2024
Hi Akshay,
 
You can access the content of the comment via the value property on the comment object, so if you change the last line of your code to const commentContent=comments[0].value , you should get the desired result.
 
Let me know if you have any questions.
 
Tipene