Skip to main content

Closing Unassigned chats with API

Introduction

Unassigned chats occur when the Asynchronous Communication feature is enabled for your LiveChat. Your agents are able to reopen the chats created when they were offline and the ones where the customer left the queue. It is a great feature helping you to make sure no communication and potential deal is missed!

Sometimes, because of an error or some unexpected situation, there are many unnecessary Unassigned chats created and there is no need for your agents to browse through all of them. Closing Unassigned chats in bulk is not available in LiveChat agent application, but it can be done with the use of LiveChat API. In this guide, we will show what methods can be used to prepare a script that will close all Unassigned chats.

Required methods

Authorization

You can authorize your requests to the LiveChat API using PAT as presented in our List Archives guide, or using Bearer token.

Fetching unassigned chats' IDs

First of all our custom script would need to collect all the unassigned chat IDs from LiveChat API using the list_archives method. Remember about the pagination - list_archives returns up to 100 records at once. Here’s an example of the request that will return all unassigned chats.

curl --location 'https://api.livechatinc.com/v3.5/agent/action/list_archives' \
--header 'Authorization: Bearer {{livechat_bearer}}' \
--header 'Content-Type: application/json' \
--data '{
"filters": {
"properties": {
"routing": {
"unassigned": {
"values": [
true
]
},
"pinned": {
"values": [
true
]
}
}
}
},
"limit": 100
}'

The response will contain the chat_id of each chat. In the filter, we use the pinned property to make sure we are getting only the unassigned chats that are not pinned. The pinned property is set to true when the chat is an Unassigned one.

You need to collect chat_ids (not thread_ids) here, so for every request it would be something like this: let chat_ids = response.json().chats.map(chat => chat.id) - depending on what method or programming language you use, it may look different.

Closing the chats

Once you obtain the required chat IDs of the unassigned chats, they need to be closed using the update_chat_properties method. You need to create an automatic script that would send a request to the LiveChat API for each chat_id you want to close. Each chat needs to be closed with a separate request. Here is an example of the request you could use:

curl --location 'https://api.livechatinc.com/v3.5/agent/action/update_chat_properties' \
--header 'Authorization: Bearer {{livechat_bearer}}' \
--header 'Content-Type: application/json' \
--data '{
"id": "",
"properties": {
"routing": {
"pinned": false
}
}
}'

The above request changes the pinned property of the chat to false, which means that the chat will no longer be Unassigned. The id property should be set to the chat_id of the chat you want to close.

If you have any questions, let us know!

Yours, Text Team 💛