Get file or directory contents
This endpoints is used to retrieve the contents of a single file, or the contents of a directory at a specified revision.
Raw file contents
When path points to a file, this endpoint returns the raw contents.
The response’s Content-Type is derived from the filename
extension (not from the contents). The file contents are not processed
and no character encoding/recoding is performed and as a result no
character encoding is included as part of the Content-Type.
The Content-Disposition header will be “attachment” to prevent
browsers from running executable files.
If the file is managed by LFS, then a 301 redirect pointing to Atlassian’s media services platform is returned.
The response includes an ETag that is based on the contents of the file
and its attributes. This means that an empty __init__.py always
returns the same ETag, regardless on the directory it lives in, or the
commit it is on.
File meta data
When the request for a file path includes the query parameter
?format=meta, instead of returning the file’s raw contents, Bitbucket
instead returns the JSON object describing the file’s properties:
$ curl https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef/tests/__init__.py?format=meta
{
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/__init__.py"
},
"meta": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/__init__.py?format=meta"
}
},
"path": "tests/__init__.py",
"commit": {
"type": "commit",
"hash": "eefd5ef5d3df01aed629f650959d6706d54cd335",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/commit/eefd5ef5d3df01aed629f650959d6706d54cd335"
},
"html": {
"href": "https://bitbucket.org/atlassian/bbql/commits/eefd5ef5d3df01aed629f650959d6706d54cd335"
}
}
},
"attributes": [],
"type": "commit_file",
"size": 0
}
File objects contain an attributes element that contains a list of
possible modifiers. Currently defined values are:
link– indicates that the entry is a symbolic link. The contents of the file represent the path the link points to.executable– indicates that the file has the executable bit set.subrepository– indicates that the entry points to a submodule or subrepo. The contents of the file is the SHA1 of the repository pointed to.binary– indicates whether Bitbucket thinks the file is binary.
This endpoint can provide an alternative to how a HEAD request can be used to check for the existence of a file, or a file’s size without incurring the overhead of receiving its full contents.
Directory listings
When path points to a directory instead of a file, the response is a
paginated list of directory and file objects in the same order as the
underlying SCM system would return them.
For example:
$ curl https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef/tests
{
"pagelen": 10,
"values": [
{
"path": "tests/test_project",
"type": "commit_directory",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/test_project/"
},
"meta": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/test_project/?format=meta"
}
},
"commit": {
"type": "commit",
"hash": "eefd5ef5d3df01aed629f650959d6706d54cd335",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/commit/eefd5ef5d3df01aed629f650959d6706d54cd335"
},
"html": {
"href": "https://bitbucket.org/atlassian/bbql/commits/eefd5ef5d3df01aed629f650959d6706d54cd335"
}
}
}
},
{
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/__init__.py"
},
"meta": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/__init__.py?format=meta"
}
},
"path": "tests/__init__.py",
"commit": {
"type": "commit",
"hash": "eefd5ef5d3df01aed629f650959d6706d54cd335",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/commit/eefd5ef5d3df01aed629f650959d6706d54cd335"
},
"html": {
"href": "https://bitbucket.org/atlassian/bbql/commits/eefd5ef5d3df01aed629f650959d6706d54cd335"
}
}
},
"attributes": [],
"type": "commit_file",
"size": 0
}
],
"page": 1,
"size": 2
}
When listing the contents of the repo’s root directory, the use of a trailing slash at the end of the URL is required.
The response by default is not recursive, meaning that only the direct contents of
a path are returned. The response does not recurse down into
subdirectories. In order to “walk” the entire directory tree, the
client can either parse each response and follow the self links of each
commit_directory object, or can specify a max_depth to recurse to.
The max_depth parameter will do a breadth-first search to return the contents of the subdirectories
up to the depth specified. Breadth-first search was chosen as it leads to the least amount of
file system operations for git. If the max_depth parameter is specified to be too
large, the call will time out and return a 555.
Each returned object is either a commit_file, or a commit_directory,
both of which contain a path element. This path is the absolute path
from the root of the repository. Each object also contains a commit
object which embeds the commit the file is on. Note that this is merely
the commit that was used in the URL. It is not the commit that last
modified the file.
Directory objects have 2 representations. Their self link returns the
paginated contents of the directory. The meta link on the other hand
returns the actual directory object itself, e.g.:
{
"path": "tests/test_project",
"type": "commit_directory",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/test_project/"
},
"meta": {
"href": "https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/eefd5ef5d3df01aed629f650959d6706d54cd335/tests/test_project/?format=meta"
}
},
"commit": { ... }
}
Querying, filtering and sorting
Like most API endpoints, this API supports the Bitbucket querying/filtering syntax and so you could filter a directory listing to only include entries that match certain criteria. For instance, to list all binary files over 1kb use the expression:
size > 1024 and attributes = "binary"
which after urlencoding yields the query string:
?q=size%3E1024+and+attributes%3D%22binary%22
To change the ordering of the response, use the ?sort parameter:
.../src/eefd5ef/?sort=-size
See filtering and sorting for more details.
Authorizations
Section titled “ Authorizations ”Parameters
Section titled “ Parameters ”Path Parameters
Section titled “ Path Parameters ”The commit’s SHA1.
Path to the file.
This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}.
This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}.
Query Parameters
Section titled “ Query Parameters ”If ‘meta’ is provided, returns the (json) meta data for the contents of the file. If ‘rendered’ is provided, returns the contents of a non-binary file in HTML-formatted rendered markup. The ‘rendered’ option only supports these filetypes: .md, .markdown, .mkd, .mkdn, .mdown, .text, .rst, and .textile. Since Git does not generally track what text encoding scheme is used, this endpoint attempts to detect the most appropriate character encoding. While usually correct, determining the character encoding can be ambiguous which in exceptional cases can lead to misinterpretation of the characters. As such, the raw element in the response object should not be treated as equivalent to the file’s actual contents.
Optional filter expression as per filtering and sorting.
Optional sorting parameter as per filtering and sorting.
If provided, returns the contents of the repository and its subdirectories recursively until the specified max_depth of nested directories. When omitted, this defaults to 1.
Responses
Section titled “ Responses ”If the path matches a file, then the raw contents of the file are
returned. If the format=meta query parameter is provided,
a json document containing the file’s meta data is
returned. If the format=rendered query parameter is provided,
the contents of the file in HTML-formated rendered markup is returned.
If the path matches a directory, then a paginated
list of file and directory entries is returned (if the
format=meta query parameter was provided, then the json document
containing the directory’s meta data is returned.)
A paginated list of commit_file and/or commit_directory objects.
object
Total number of objects in the response. This is an optional element that is not provided in all responses, as it can be expensive to compute.
Page number of the current results. This is an optional element that is not provided in all responses.
Current number of objects on the existing page. The default value is 10 with 100 being the maximum allowed value. Individual APIs may enforce different values.
Link to the next page if it exists. The last page of a collection does not have this value. Use this link to navigate the result set and refrain from constructing your own URLs.
Link to previous page if it exists. A collections first page does not have this value. This is an optional element that is not provided in all responses. Some result sets strictly support forward navigation and never provide previous links. Clients must anticipate that backwards navigation is not always available. Use this link to navigate the result set and refrain from constructing your own URLs.
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
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.
Example
{ "values": [ { "commit": { "summary": { "markup": "markdown" }, "repository": { "scm": "git", "fork_policy": "allow_forks", "mainbranch": { "merge_strategies": [ "merge_commit" ] } }, "participants": [ { "role": "PARTICIPANT", "state": "approved" } ] } } ]}If the path or commit in the URL does not exist.
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": {} }}If the call times out, possibly because the specified recursion depth is too large.
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": {} }}