How to get Conversation of a ticket in any sorting order Using API

Hi @channel,

I am trying to list the conversation of a ticket in the descending order using (order_type=desc) but its not working in API . Is there any other solution listing conversation in sorting orders using API . If possible please share the solution.

Thanks

HI @Gokul_Chakkaravarthi

Good Day!

As per the documentation, we can able to get the conversation of the particular ticket with the help of this endpoint /api/v2/tickets/[id]?include=conversations by default it will return 10 conversations and the result will be sorted in ascending order.

I don’t find the right API for your use case, I will check with the team and keep you posted.

Thanks

Hi @Gokul_Chakkaravarthi ,

Adding to Sujith’s words,

order_type would work fine for tickets and not for conversations. Also, I’m not sure of the endpoint you’re currently relying on and on what param you’re trying to sort, if it’s /api/v2/tickets/[id]?include=conversations it would work as mentioned above. In case if you need all the conversations please use Freshdesk

In both cases, assuming the number doesn’t exceed 20 in most cases (having said they are conversations in a ticket) there shouldn’t be an issue in sorting client side. Though not the best solution you’d be seeking for, this could unblock you I guess.

By default, the conversations are sorted in ascending order in terms of created_at timestamp. As the timestamp is in UTC, you can apply sort on the response using simple compare function as below,

function compare( a, b ) {
  if ( a.created_at > b.created_at ){
    return -1;
  }
  if ( a.created_at < b.created_at ){
    return 1;
  }
  return 0;
}

obj.sort(compare);

Thanks

There could be more than 100 conversation in the ticket but I would need most recent four conversations. Could you help me to get it ?

Hi @Gokul_Chakkaravarthi

Unfortunately, This is currently not possible with Freshdesk API. we will take this as feedback and forward it to the Freshdesk API team. Please check with @mariappan suggestion but I suspect it will cause a request API rate limit error.

thanks

Sorry, this is not possible.

As of now, the responses are paginated and you’ll get 30 conversations in each page. One possible solution I could think of is getting the total conversations available as part of payload. So that you can hit with the right end threshold to get the latest tickets & sort as above. Sorting would not cause any API rate limit error, making repeated calls through the pagination might lead to.

I’ll request the team to get this be added to tracker of feature requests (if not already) as I can find other instances of tickets requesting the same - How to fetch latest 10 conversations in a ticket - #12 by RobAtOpinyin

Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.