Search for code in a workspace
This API will be deprecated on November 1, 2026.
Search for code in the repositories of the specified workspace.
Note that searches can match in the file’s text (content_matches),
the path (path_matches), or both.
You can use the same syntax for the search query as in the UI.
E.g. to search for “foo” only within the repository “demo”,
use the query parameter search_query=foo+repo:demo.
Similar to other APIs, you can request more fields using a
fields query parameter. E.g. to get some more information about
the repository of matched files, use the query parameter
search_query=foo&fields=%2Bvalues.file.commit.repository
(the %2B is a URL-encoded +).
Try fields=%2Bvalues.*.*.*.* to get an idea what’s possible.
Authorizations
Section titled “ Authorizations ”Parameters
Section titled “ Parameters ”Path Parameters
Section titled “ Path Parameters ”The workspace to search in; either the slug or the UUID in curly braces
Query Parameters
Section titled “ Query Parameters ”The search query
Which page of the search results to retrieve
How many search results to retrieve per page
Responses
Section titled “ Responses ”Successful search
object
object
object
object
object
object
A file object, representing a file at a commit in a repository
object
The path in the repository
object
object
The raw author value from the repository. This may be the only value available if the author does not match a user in Bitbucket.
object
Links related to an Account.
object
A link to a resource related to this object.
object
object
The raw committer value from the repository. This may be the only value available if the committer does not match a user in Bitbucket.
object
Links related to an Account.
object
A link to a resource related to this object.
object
object
The text as it was typed by a user.
The type of markup language the raw content is to be interpreted in.
The user’s content rendered as HTML.
object
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
The repository’s immutable id. This can be used as a substitute for the slug segment in URLs. Doing this guarantees your URLs will survive renaming of the repository by its owner, or even transfer of the repository to a different user.
The concatenation of the repository owner’s username and the slugified name, e.g. “evzijst/interruptingcow”. This is the same string used in Bitbucket URLs.
object
Links related to an Account.
object
A link to a resource related to this object.
object
The issue tracker for this repository is enabled. Issue Tracker features are not supported for repositories in workspaces administered through admin.atlassian.com.
The wiki for this repository is enabled. Wiki features are not supported for repositories in workspaces administered through admin.atlassian.com.
Controls the rules for forking this repository.
- allow_forks: unrestricted forking
- no_public_forks: restrict forking to private forks (forks cannot be made public later)
- no_forks: deny all forking
object
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
The project’s immutable id.
The project’s key.
object
Links related to an Account.
object
A link to a resource related to this object.
object
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
The name of the project.
Indicates whether the project is publicly accessible, or whether it is private to the team and consequently only visible to team members. Note that private projects cannot contain public repositories.
Indicates whether the project contains publicly visible repositories. Note that private projects cannot contain public repositories.
object
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
A link to a resource related to this object.
object
The name of the ref.
Available merge strategies for pull requests targeting this branch.
The default merge strategy for pull requests targeting this branch.
object
object
Links related to an Account.
object
A link to a resource related to this object.
object
The ISO8601 timestamp of the participant’s action. For approvers, this is the time of their approval. For commenters and pull request reviewers who are not approvers, this is the time they last commented, or null if they have not commented.
The escaped version of the path as it appears in a diff. If the path does not require escaping this will be the same as path.
Examples
{ "size": 1, "page": 1, "pagelen": 10, "query_substituted": false, "values": [ { "type": "code_search_result", "content_match_count": 2, "content_matches": [ { "lines": [ { "line": 2, "segments": [] }, { "line": 3, "segments": [ { "text": "def " }, { "text": "foo", "match": true }, { "text": "():" } ] }, { "line": 4, "segments": [ { "text": " print(\"snek\")" } ] }, { "line": 5, "segments": [] } ] } ], "path_matches": [ { "text": "src/" }, { "text": "foo", "match": true }, { "text": ".py" } ], "file": { "path": "src/foo.py", "type": "commit_file", "links": { "self": { "href": "https://api.bitbucket.org/2.0/repositories/my-workspace/demo/src/ad6964b5fe2880dbd9ddcad1c89000f1dbcbc24b/src/foo.py" } } } } ]}If the search request was invalid due to one of the following reasons:
-
the specified type of target account doesn’’t match the actual account type;
-
malformed pagination properties;
-
missing or malformed search query, in the latter case an error key will be returned in
error.data.keyproperty.
Base type for most resource objects. It defines the common type element that identifies an object’s type. It also identifies the element as Swagger’s discriminator.
object
object
Optional structured data that is endpoint-specific.
object
Example generated
{ "type": "example", "error": { "message": "example", "detail": "example", "data": {} }}Search is not enabled for the requested workspace, navigate to https://bitbucket.org/search to turn it on
Base type for most resource objects. It defines the common type element that identifies an object’s type. It also identifies the element as Swagger’s discriminator.
object
object
Optional structured data that is endpoint-specific.
object
Example generated
{ "type": "example", "error": { "message": "example", "detail": "example", "data": {} }}Too many requests, try again later
Base type for most resource objects. It defines the common type element that identifies an object’s type. It also identifies the element as Swagger’s discriminator.
object
object
Optional structured data that is endpoint-specific.
object
Example generated
{ "type": "example", "error": { "message": "example", "detail": "example", "data": {} }}