# Search conversations > Find an agent's conversations whose messages contain a phrase, with the matching line `search_conversations` looks through the messages of an agent's conversations for a phrase, across every channel, and returns each matching conversation with its first matching message. The match is literal and case-insensitive, not semantic. To filter by state, sentiment, channel, feedback or escalation instead, use [List conversations](/docs/api-reference/v2/conversations/list-conversations). See [Conversation Search](/docs/api-reference/v2/conversation-search) for examples. ```http POST https://api.qwryai.com/public/v1/tools/search_conversations ``` ## Authentication Send your API key as `Authorization: Bearer `, or in an `x-api-key` header. The key needs **Manage conversations and helpdesk**. See [Authentication](/docs/api-reference/v2/authentication). ## Body parameters | Name | Type | Required | Description | | - | - | - | - | | `chatbotId` | `string` | Yes | The agent's id, from [List agents](/docs/api-reference/v2/agents/list-agents). | | `query` | `string` | Yes | The phrase to find, 2 to 200 characters, matched as written. | | `startDate` | `string` | Yes | Conversations created from this day, `YYYY-MM-DD` in UTC. | | `endDate` | `string` | Yes | Conversations created up to this day, included. At most 184 days after `startDate`. | | `sender` | `string` | No | Only match messages from `customer`, `ai` or `agent`. Leave it out to match any. | | `topic` | `string` | No | Only conversations tagged with this **Analytics** topic. | | `limit` | `integer` | No | Results to return, 1 to 50. Defaults to 20. | ## Request example > [tab] cURL > > ```bash > curl -X POST 'https://api.qwryai.com/public/v1/tools/search_conversations' \ > -H 'Authorization: Bearer YOUR_API_KEY' \ > -H 'Content-Type: application/json' \ > -d '{ > "chatbotId": "YOUR_AGENT_ID", > "query": "refund", > "sender": "customer", > "startDate": "2026-11-01", > "endDate": "2026-11-30" > }' > ``` > [tab] JavaScript > > ```javascript > const response = await fetch("https://api.qwryai.com/public/v1/tools/search_conversations", { > method: "POST", > headers: { > Authorization: "Bearer YOUR_API_KEY", > "Content-Type": "application/json", > }, > body: JSON.stringify({ > chatbotId: "YOUR_AGENT_ID", > query: "refund", > sender: "customer", > startDate: "2026-11-01", > endDate: "2026-11-30", > }), > }); > const { data } = await response.json(); > for (const item of data.items) console.log(item.match.excerpt); > ``` > [tab] Python > > ```python > import requests > > response = requests.post( > "https://api.qwryai.com/public/v1/tools/search_conversations", > headers={"Authorization": "Bearer YOUR_API_KEY"}, > json={ > "chatbotId": "YOUR_AGENT_ID", > "query": "refund", > "sender": "customer", > "startDate": "2026-11-01", > "endDate": "2026-11-30", > }, > ) > for item in response.json()["data"]["items"]: > print(item["match"]["excerpt"]) > ``` ## Response ```json { "success": true, "data": { "items": [ { "conversation": { "_id": "CONVERSATION_RECORD_ID", "conversationId": "3c3766ae-0119-4687-b992-a7f6219d9b29", "channel": "whatsapp", "lifecycle": "open", "metadata": { "aiSummary": "Customer asks when the refund for order 1042 will arrive." }, "timestamps": { "created": "2026-11-09T18:29:40.658Z", "lastActivity": "2026-11-09T18:41:02.114Z" }, "metrics": { "messageCount": 8, "aiMessageCount": 4, "agentMessageCount": 0 }, "insights": { "sentiment": "negative" } }, "match": { "sender": "customer", "timestamp": "2026-11-09T18:32:37.261Z", "excerpt": "I returned the jacket last week, when will my refund for order 1042 come through?", "matchingMessages": 2, "customerMatches": 2 } } ], "searchedConversations": 391, "conversationsInRange": 391, "range": { "startDate": "2026-11-01", "endDate": "2026-11-30" }, "timezone": "UTC", "sender": "customer", "coverage": "Case-insensitive literal match on customer message text in the 391 most recent conversations created in this range. Not semantic search." } } ``` | Field | Description | | - | - | | `items[].conversation` | The conversation, with the same fields as [List conversations](/docs/api-reference/v2/conversations/list-conversations). Pass its `_id` to [Get a conversation](/docs/api-reference/v2/conversations/get-a-conversation). | | `items[].match.sender` | Who wrote the first matching message: `customer`, `ai` or `agent`. | | `items[].match.excerpt` | Up to 300 characters of that message. | | `items[].match.matchingMessages` | How many messages in the conversation matched. | | `items[].match.customerMatches` | How many of those the customer wrote. | | `searchedConversations` | How many conversations were searched. | | `conversationsInRange` | How many conversations the range holds. | | `coverage` | What was searched, in words. | > [!NOTE] > > Search looks through the 2,000 most recent conversations in the range and isn't paged. When `conversationsInRange` is larger than `searchedConversations`, narrow the dates to reach older conversations. ## Errors | HTTP status | Code | When | | - | - | - | | 400 | `INVALID_ARGUMENTS` | `query` is missing or under 2 characters, a date isn't `YYYY-MM-DD`, or `limit` is out of range. `issues` lists each one. | | 400 | `CHATBOT_ID_REQUIRED` | The body has no valid `chatbotId`. | | 401 | `API_KEY_REQUIRED` / `INVALID_API_KEY` | No credential, or an unknown, deleted or expired one. | | 403 | `INSUFFICIENT_PERMISSION` | The key doesn't hold **Manage conversations and helpdesk**. | | 404 | `CHATBOT_NOT_FOUND` | No agent with that `chatbotId` in your workspace. | | 409 | `VALIDATION_INVALID_BODY` | `endDate` is before `startDate`, or the range is longer than 184 days. | | 413 | `RESULT_TOO_LARGE` | The answer is over 40,000 bytes. Lower `limit`. | | 429 | `INTEGRATION_RATE_LIMIT_EXCEEDED` | More than 2,000 requests in 15 minutes. | See [Error Handling](/docs/api-reference/v2/error-handling) for every code.