Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

What is the API used to get file contents?

Mohammed Muthahhar January 5, 2023

Hi,

Are there any APIs for getting the content of a file without giving the sha of the commit which is mentioned here..

https://developer.atlassian.com/cloud/bitbucket/rest/api-group-source/#api-repositories-workspace-repo-slug-src-commit-path-get 

 

I tried  https://api.bitbucket.org/2.0/repositories/myorg/myrepo/src/master/filename url to read the file and it works fine.

But if it's a feature branch or bugfix etc, and if we try  https://api.bitbucket.org/2.0/repositories/myorg/myrepo/src/feature/my-branch/filename

it gives error as

{
    "type": "error",
    "error": {
        "message": "Commit not found",
        "data": {
            "shas": [
                "bugfix"
            ]
        }
    },
    "data": {
        "shas": [
            "bugfix"
        ]
    }
}
what is the solution for this??

1 answer

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 10, 2023

Hi @Mohammed Muthahhar,

This endpoint works with branch names that don't include the slash character ( / ) but it will not work for branches that have a slash in their name.

We have a bug report in our issue tracker here:

The bug report mentions the commit endpoint, but this applies to the src endpoint as well.

For these branches that include a slash in their name, you will need to provide a commit hash instead. You can use the following endpoint to get the commit hash of a branch's last commit:

You can filter the output to return only the commit hash with a url as follows:

https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/refs/branches/feature/mu-feature-branch?fields=target.hash

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events