Skip to content
WhatSync/DocsAPI v1

Search WhatsApp messages

Search stored WhatsApp message text, attachment filenames, sender names, permitted file and voice-note readings, and chats by their saved contact or group name.

POST/api/v1/tools/search_messagesRead
Key permissions
Read chats and messages
Authentication
Authorization: Bearer $WHATSYNC_API_KEY
How keys work

How it works

  • Words match in any order; plurals also find the singular; amounts match with or without commas; accented words also find the unaccented spelling; a phone number (7+ digits, with or without country code) also matches chat numbers; an empty query lists the newest messages.
  • Matching is by letters, not meaning or translation; up to 10 spellings, alphabets or related words can be combined in one query with OR (e.g.
  • "Mohammed OR Muhammad OR محمد").
  • When a search reaches back past the first saved message, saved_history gives the date saved messages start.
  • Pass a known conversation_id as conversationId, and date filters when known.
  • Searches default to 180 days; a longer window than 366 days is shortened to the 366 days ending at before, and the result says so.
  • When a page is not the whole period, page_coverage gives the time the shown messages cover.

Body parameters

querystringoptional

Words or phrase to search for; leave empty to list the newest messages in the date window, conversation and direction given

conversationIdstringoptional

A conversation_id returned by another WhatSync tool, to limit the search to one conversation

directioninbound | outboundoptional

Limit matches by message direction

afterstring · date-timeoptional

Search messages at or after this ISO timestamp

beforestring · date-timeoptional

Search messages before this ISO timestamp; must be later than after

cursorstringoptional

Opaque next_cursor returned by the previous page

limitintegeroptional

Number of matches to return; defaults to 20, at most 50. With an empty query: defaults to 100 (a limit of 50 also gets 100), at most 200

mentionsMebooleanoptional

Only messages where someone @tagged this WhatsApp number

Conditions and pagination

  • Pass the returned next_cursor unchanged as cursor, keeping the same filters. Stop when it is null. A page is not the complete history.

Response

HTTP 200 returns this tool's JSON directly, without an MCP content wrapper. Optional provider fields may be absent or null; check pagination and coverage before treating a page as complete.

Every response includes X-Request-Id. Errors use the shared error format and retry rules.

Schemas

Input JSON Schema
Input JSON Schema
{
  "type": "object",
  "properties": {
    "query": {
      "type": "string",
      "maxLength": 300,
      "description": "Words or phrase to search for; leave empty to list the newest messages in the date window, conversation and direction given"
    },
    "conversationId": {
      "type": "string",
      "maxLength": 250,
      "description": "A conversation_id returned by another WhatSync tool, to limit the search to one conversation"
    },
    "direction": {
      "type": "string",
      "enum": [
        "inbound",
        "outbound"
      ],
      "description": "Limit matches by message direction"
    },
    "after": {
      "type": "string",
      "format": "date-time",
      "description": "Search messages at or after this ISO timestamp"
    },
    "before": {
      "type": "string",
      "format": "date-time",
      "description": "Search messages before this ISO timestamp; must be later than after"
    },
    "cursor": {
      "type": "string",
      "maxLength": 600,
      "description": "Opaque next_cursor returned by the previous page"
    },
    "limit": {
      "type": "integer",
      "minimum": 1,
      "maximum": 200,
      "description": "Number of matches to return; defaults to 20, at most 50. With an empty query: defaults to 100 (a limit of 50 also gets 100), at most 200"
    },
    "mentionsMe": {
      "type": "boolean",
      "description": "Only messages where someone @tagged this WhatsApp number"
    }
  },
  "additionalProperties": false,
  "$schema": "http://json-schema.org/draft-07/schema#"
}
Response JSON Schema
Response JSON Schema
{
  "type": "object",
  "properties": {
    "page_coverage": {
      "type": "object",
      "properties": {
        "complete": {
          "type": "boolean"
        },
        "messages_shown": {
          "type": "number"
        },
        "shown_from": {
          "type": "string"
        },
        "shown_to": {
          "type": "string"
        },
        "asked_from": {
          "type": "string"
        },
        "asked_to": {
          "type": "string"
        }
      },
      "required": [],
      "additionalProperties": true
    },
    "messages": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "message_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "conversation_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "channel": {
            "type": [
              "string",
              "null"
            ]
          },
          "sent_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "direction": {
            "type": [
              "string",
              "null"
            ]
          },
          "sender": {
            "type": [
              "string",
              "null"
            ]
          },
          "recipient": {
            "type": [
              "string",
              "null"
            ]
          },
          "contact_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "group_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "participant_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "provider_phone_number_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "quoted_message_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "delivery_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "type": {
            "type": [
              "string",
              "null"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ]
          },
          "attachment": {
            "anyOf": [
              {
                "type": "object",
                "additionalProperties": true,
                "description": "Provider or tool-specific fields; preserve unknown fields."
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [],
        "additionalProperties": true
      }
    },
    "has_more": {
      "type": "boolean"
    },
    "searched_after": {
      "type": "string"
    },
    "searched_before": {
      "type": "string"
    },
    "message_access_starts_at": {
      "type": "string"
    },
    "next_before": {
      "type": [
        "string",
        "null"
      ]
    },
    "next_cursor": {
      "type": [
        "string",
        "null"
      ]
    },
    "note": {
      "type": "string"
    }
  },
  "required": [],
  "additionalProperties": true
}