How do I grab the thread in a custom function?

How do I grab the thread in a custom function?

I need the sample code for grabbing thread content from an email and put it in ticket description.

Do I need to make an API call for this? 

When I tried making an API call for the thread content, I got an error for: 
{"errorCode":"UNAUTHORIZED","message":"You are not authenticated to perform this operation."}

What am I missing from this code?
con = invokeurl
[
url: "https://desk.zoho.com/api/v1/tickets/"+ticketId+"/conversations"
type: GET
];