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
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:
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.