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

how to intergrate java with bitbucket, for sharing files to bitbucket account?

Edited

i am trying to create a java application for sending files to bitbucket using atlasian cloud rest-api's provided by atlasian. My goal here is to send files to bitbucket account without logging in to bitbucket account. the official document says that generate token and use it but its too confusing, coz we can generate many types of token in bitbucket account, please tell me how to create a access token and how to use it to access workspaces and repositories for sending files to workpaces or repositories, thanks in advance

1 answer

1 accepted

1 vote
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Mar 16, 2023

Hello @srinath reddy ,

Thank you for reaching out to Atlassian Community!

You can use an OAuth consumer in order to generate an access token that can then be used to authenticate calls to Bitbucket Cloud Public API. Let me share below the steps for using OAuth client credential flow:

  1. Create an OAuth consumer under the desired workspace. The callback URL can be defined as https://localhost and make sure to mark the checkbox This is a private consumer so it enables the client credential flow. The scopes to be selected in the OAuth consumers will depend on what API endpoints you would like to call. For example, if you would like to write to a repository, you will need an Oauth consumer that has at least repo:read and repo:write permissions.
  2. After creating the OAuth consumer, you will be given a Key and Secret than can be exchanged by an Access token. Use the following API endpoint to exchange the consumer credentials for an access token :
    curl -X POST -u "Key:Secret" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials

    Please note that access tokens expire in 2 hours, and you will need to call the endpoint above again to generate a new access token.

  3. Use the access token to authenticate an API call. In this example we are using the Create a commit by uploading a file endpoint :
    curl -X POST https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/src \
    --header 'Authorization: Bearer <Access Token>' -F path/within/repo/myfile.txt=@file_to_upload.txt

    This will create a new commit on the main branch adding a file named myfile.txt inside the path/within/repo directory of your repository.

For more details on authentication methods and available endpoints, you're also welcome to check Bitbucket Cloud public API reference.

Alternatively, we have recently released Repository Access Tokens (RATs) in Bitbucket Cloud that can also be used to authenticate API calls. In case would to learn more about RATs, and how to create and use them, I would recommend taking a look at our Repository Access Tokens documentation.

Hope that helps! Let me know if you have any questions.

Thank you, @srinath reddy !

Patrik S

Hii, @Patrik S 
thanks for the reply,
i'm working on it.

Suggest an answer

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

Atlassian Community Events