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.
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.
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);
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.
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.