Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

What is the API used to get file contents?

Edited

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

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Jan 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