Skip to main content

search.messages method

Welcome to the new home of Slack developer docs!

We're still building and not all features are available quite yet. Enjoy this peek into the future!

Not ready for the future? Return to the past at api.slack.com.

Usage info

This method returns messages matching a search query.

The team_id is only relevant when using an org-level token. This field will be ignored if the API call is sent using a workspace-level token.

Response

The matching items are returned as hashes containing contextual messages. This response envelope also contains paging and result information.

When using a user token with this method, search results will be affected by the search filters set in the Slack UI. When a search query matches multiple messages in close proximity to one another, only one match will be returned. Using the highlights=true parameter, you can identify which items match the query, and which are provided for context only.

Note: Previously, search results might be returned with matches on the previous, previous_2, next, or next_2 messages, but not the message itself. However, the previous, previous_2, next, or next_2 fields are now deprecated and will no longer be provided in responses beginning December 3, 2020.

If more than one search term is provided, users and channels are also matched at a lower priority. To specifically search within a channel, group, or DM, add in:channel_name, in:group_name, or in:<@UserID>. To search for messages from a specific speaker, add from:<@UserID> or from:botname.

For IM results, the type is set to "im" and the channel.name property contains the user ID of the target user. For private group results, type is set to "group".

All search methods support the highlight parameter. If specified, the matching query terms will be marked up in the results so that clients may replace them with appropriate highlighting markers (e.g. <span class="highlight"></span>). The UTF-8 markers we use are:

start: "\xEE\x80\x80"; # U+E000 (private-use)
end : "\xEE\x80\x81"; # U+E001 (private-use)

Please note that the max count value is 100 and the max page value is 100.