Bulk Assigning Conversations to a Teammate

Welcome! This guide will help you create a script to assign a list of conversations based on a search query to another user in bulk. Don't worry if you're new to Ruby, GraphQL, or APIs in general; we'll walk you through it step by step!

We'll be using a query described in List All Conversations and adding some additional steps for searching. To assign a conversation, we'll use the Conversation Assign Mutation .

Installing Ruby (or use an online tool)


If you don't already have Ruby installed on your computer, you can follow the instructions below to get set up. Alternatively, if you'd rather not install Ruby, you can use an online tool like to run the script.



Before you start, make sure you have your Access Token handy. You'll need to insert it into the script for it to work. If you're not sure where to find your Access Token, check out our Quickstart guide. Please note that you must have a Read/Write token for this script to work.

This Ruby script fetches a list of conversations based on a search query and assigns them to another user in bulk. Let's break it down into sections and explain what each section does:

1. Loading required libraries and setting up constants


This section loads the required libraries for handling HTTP requests, SSL, JSON, and URIs. It also sets up the ACCESS_TOKEN, URL, OLD_ASSIGNEE_ID, and NEW_ASSIGNEE_ID constants. Replace the placeholder values with your actual access token and user IDs.

2. Defining GraphQL queries and mutations


This section defines the necessary GraphQL queries and mutations that the script will use to fetch the conversations and assign them to the new user.

3. Function: fetch_assigned_conversations


This function fetches all conversations that match the search query. It uses a while loop to paginate through the conversations, making API requests until there are no more conversations to fetch. Finally, it returns the fetched conversations.

4. Function: assign_conversations


This function assigns the fetched conversations to the new user. It calls the fetch_assigned_conversations function to fetch the conversations and then iterates through them, assigning each conversation to the new user using the ASSIGN_CONVERSATION_MUTATION . It also handles errors and prints the status of the assignment process.

5. Function: raise_error!(error)


This function is a helper function to raise an ArgumentError if there's an error in the GraphQL response.

6. Function: make_request(query, variables = {})


This function is a helper function to make HTTP requests to the API with the specified GraphQL query and variables. It sets up the necessary headers, creates the request body, sends the request, and parses the response.

7. Calling the main function


This line calls the assign_conversations function to start the process of fetching and assigning conversations in bulk.

In summary, this script fetches a list of conversations based on a search query and assigns them to another user in bulk using the Rasayel API and GraphQL. The script is organized into functions that handle fetching conversations, assigning them, making API requests, raising errors, and executing the main function to fetch and assign conversations.

The Full Script