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

How can I view/read a file from BitBucket using API?

Blessie Labayna
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 6, 2022

I have a json file stored in BitBucket. My goal is to view the json file as a raw using Postman or invoking an HTTPS request.

 

https://bitbucket.org/<repo>/<project>/raw/master/config_test.json?response=json

The URL above works fine when I view it from the browser, but now when I call it from postman. I even tried the api.bitbucket.org/2.0/repositories but still not working.

I'm getting this error

{
    "type""error",
    "error": {
        "message""Resource not found",
        "detail""There is no API hosted at this URL.\n\nFor information about our API's, please refer to the documentation at: https://developer.atlassian.com/bitbucket/api/2/reference/"
    }
}
I have already tried creating an app password and using Authorization: Bearer <token> but still unsuccessful.

2 answers

1 accepted

1 vote
Answer accepted
Caterina Curti
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 5, 2023

Hello!

I just wrote an article about how to read a file from the REST API: https://community.atlassian.com/t5/Bitbucket-articles/Reading-a-file-from-a-repository-in-Bitbucket-using-the-REST-API/ba-p/2552394

Hope this will be helpful!

Cheers,
Caterina

0 votes
seanaty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 7, 2022

Requesting in your browser works because it is likely using your session cookie to authenticate.

For API authentication, here are some ideas of what to check.

1. Definitely use api.bitbucket.org/2.0/...

2. The app password needs your username still, it is not a bearer token. e.g. you need to use curl -u my-username:my-app-password https://api.bitbucket.org/2.0/repositories/...

This is the API you'll want to use to get a file: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-source/#api-repositories-workspace-repo-slug-src-commit-path-get as the first "raw" URL you posted isn't an API resource.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events