Skip to main content

Search conversations

Search your account's conversations by contact name, phone number and message text in one call. It is the same search your team uses from the search box of the live chat, and it returns two groups of results:

  • contacts: the conversations whose contact name or phone number matches the term, one result per contact. The top matches are returned, not paginated.
  • messages: the individual messages whose text matches the term, newest first, paginated.

Each result carries the session_key of its conversation, so you can pass it straight to the other Conversations endpoints, or fetch the messages of that conversation.

Endpoint​

GET https://api.p.2chat.io/open/search

Authentication​

Include your API key in the X-User-API-Key header. Learn more about authentication.

API cost​

5API credits

Each call to this endpoint deducts 5 API credits from your plan's API credit pool.

This endpoint runs the contact search and the message search over the whole account in one call, so it costs more than the usual 1 credit of other /open/ endpoints.

Permissions​

The search runs as the user who owns the API key, with the same visibility as in the live chat. An admin searches every conversation of the account. Any other user only finds conversations they can open: those of a number shared with them, or those assigned to them or to one of their teams.

Parameters​

These parameters are sent as query string parameters.

FieldTypeRequiredDescription
qstringYesThe search term, at least 2 characters. Matched against the contact's name, their phone number and the text of the messages. Examples: Kate, 5550147, invoice
page_numberintegerNoZero-based page of the messages group. Defaults to 0. The contacts group is not paginated
results_per_pageintegerNoMessages returned per page, between 1 and 100. Defaults to 20
contacts_limitintegerNoMaximum number of contact matches returned, between 1 and 50. Defaults to 20

How matching works​

  • Contact names are matched by word and by partial text, ignoring accents: jose finds JosΓ© PΓ©rez, and Carl finds Carlos.
  • Phone numbers are matched on their digits. Any run of digits finds the numbers that contain it: 5550147 finds +14085550147.
  • Message text is matched by word, ignoring accents. Each message result includes a highlight with the fragment of the text where the term was found, the term wrapped in <em> tags.
  • Results come from the search index. A message received a few seconds ago may not appear yet.

Invocation​

curl --location 'https://api.p.2chat.io/open/search?q=invoice&page_number=0&results_per_page=20&contacts_limit=20' \
--header 'X-User-API-Key: your_api_key_here'

Response​

Success (HTTP 200 OK)​

{
"success": true,
"query": "invoice",
"contacts": {
"count": 1,
"results": [
{
"contact_uuid": "CON8c1f4e2a-7b3d-4f0e-9a61-2d5c8e7f1b93",
"contact_name": "Invoice Desk Β· Acme",
"phone_number": "+14085550176",
"session_key": "WA-WAN8fd3442f-e111-4fed-9323-1824fd7546c9-14085550176",
"channel_uuid": "WAN8fd3442f-e111-4fed-9323-1824fd7546c9",
"last_message_at": "2026-11-09T18:20:00Z"
}
]
},
"messages": {
"count": 2,
"page": 0,
"results_per_page": 20,
"results": [
{
"message_uuid": "MSG5e2d9c41-7a3f-4b8e-9c01-6d2f8a4b7e13",
"session_key": "WP-WPN3a9e7c15-2f84-4b6d-8e01-c7d2f9a4b5e6-5491155550123",
"channel_uuid": "WPN3a9e7c15-2f84-4b6d-8e01-c7d2f9a4b5e6",
"contact_uuid": "CONd27b0a95-41c6-4e8f-b3a2-6f1e9c0d7a48",
"contact_name": "Katerina",
"phone_number": "+5491155550123",
"text": "Could you resend the invoice for October?",
"highlight": {
"text": ["Could you resend the <em>invoice</em> for October?"]
},
"direction": "inbound",
"sent_at": "2026-11-08T13:05:42Z"
},
{
"message_uuid": "MSGa1b7c3d9-2e4f-4a6b-8c0d-1e3f5a7b9c2d",
"session_key": "WA-WAN8fd3442f-e111-4fed-9323-1824fd7546c9-14085550176",
"channel_uuid": "WAN8fd3442f-e111-4fed-9323-1824fd7546c9",
"contact_uuid": "CON8c1f4e2a-7b3d-4f0e-9a61-2d5c8e7f1b93",
"contact_name": "Invoice Desk Β· Acme",
"phone_number": "+14085550176",
"text": "Your invoice is attached. Thanks!",
"highlight": {
"text": ["Your <em>invoice</em> is attached. Thanks!"]
},
"direction": "outbound",
"sent_at": "2026-11-02T09:41:10Z"
}
]
}
}
FieldDescription
successtrue when the request was successful
queryThe search term, as it was searched
contacts.countTotal number of conversations whose contact matched, across the whole account
contacts.resultsThe top contacts_limit matches, best match first
contacts.results[].contact_uuidUUID of the contact, or null when the conversation has no contact in your account
contacts.results[].contact_nameThe contact's name as shown in the live chat
contacts.results[].phone_numberThe contact's phone number
contacts.results[].session_keyThe conversation. Use it with the other Conversations endpoints
contacts.results[].channel_uuidUUID of the connected number the conversation belongs to
contacts.results[].last_message_atWhen the most recent matching message of that conversation was sent, in UTC
messages.countTotal number of messages matching the term, across all pages
messages.pageThe zero-based page returned, echoing page_number
messages.results_per_pageThe page size used
messages.resultsThe messages on this page, newest first
messages.results[].message_uuidUUID of the message
messages.results[].session_key, channel_uuid, contact_uuid, contact_name, phone_numberThe conversation and contact the message belongs to, as in the contacts group
messages.results[].textThe text of the message
messages.results[].highlightThe fragment(s) of the text where the term matched, with the term wrapped in <em> tags
messages.results[].directioninbound when the contact sent it, outbound when your account did
messages.results[].sent_atWhen the message was sent, in UTC

Error​

{
"success": false,
"error": true,
"error_message": "Please upgrade your account to continue using this API: You have exceeded the API quota for your plan."
}
FieldDescription
errortrue when the request failed
error_messageA description of what went wrong
HTTP statusWhen
422q is missing or shorter than 2 characters, or a paging parameter is out of its range. Nothing is billed
402Your account has no API credits left. Nothing is searched
401The API key is missing or invalid