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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,461,883
Community Members
 
Community Events
176
Community Groups

Bitbucket API

Dear All,

I am exploring BitBucket Module of Python API with below URL.

https://atlassian-python-api.readthedocs.io/bitbucket.html

However, I am still can't find the right python packages to use "bitbucket"

# Project list
bitbucket.project_list()

I am keen to work for the following methods

Manage projects

Manage repositories

Manage Code Insights

Groups and admins

Manage code

Branch permissions

Pull Request management

Conditions-Reviewers management

Pipelines management

Manage issues

 

Since I am rushing for my experiment and I hope someone will advise me to move forward quickly.

 

Best regards

 

1 answer

0 votes
Vishwas Rising Star Feb 18, 2022

Hey @Kyaw  Welcome to Atlassian Community

do this install from pip

pip install atlassian-python-api

and in code use this 

from atlassian import Bitbucket

 

Link for same here https://atlassian-python-api.readthedocs.io/index.html

Hi Vishwas,

 

Thanks for your prompt reply and I used it below

from atlassian import Jira
from atlassian import Confluence
from atlassian import Bitbucket
from atlassian import ServiceDesk
from atlassian import Xray

bitbucket = Bitbucket(
       url='http://localhost:9090',
       username='admin',
       password='admin')
However, I am not able to call these APIs.
I hope you will advise me since I am new for the Atlassian APIs.
# Project list
bitbucket.project_list()
# Get single repository
bitbucket.get_repo(project_key, repository_slug)
 
# Get repositories list from project
bitbucket.repo_list(project_key, limit=25)
# Decline pull request
bitbucket.decline_pull_request(project_key, repository, pr_id, pr_version)
 
# Object oriented:
    # Get the repository first
    r = cloud.workspaces.get(workspace).repositories.get(repository)
Vishwas Rising Star Feb 19, 2022

Hey @Kyaw 

Check this link here https://github.com/atlassian-api/atlassian-python-api/blob/master/examples/bitbucket/bitbucket_cloud_oo.py

A sample example is mentioned there.

Let me know in case of any questions.

Hi Vishwas,

 

Thanks for your help and pls advise me where can I have this URL https://api.bitbucket.org.

Since I have only this https://bitbucket.org/mrkyawkyawoo/

Also could it be possible to experiment locally first like below

bitbucket = Bitbucket(
       url='http://localhost:9090',
       username='admin',
       password='admin')
Best regards
Vishwas Rising Star Feb 19, 2022

Hey @Kyaw 

You are in bitbucket cloud.

so the api url to be used is https://api.bitbucket.org

This part is authentication for server which doesn't work in your case

 

bitbucket = Bitbucket(
       url='http://localhost:9090',
       username='admin',
       password='admin')
Check this part in the doc :
# Log-in with E-Mail / Username and regular password
# or with Username and App password.
# Get App password from https://bitbucket.org/account/settings/app-passwords/.
# Log-in with E-Mail and App password not possible.
# Username can be found here: https://bitbucket.org/account/settings/

from atlassian.bitbucket import Cloud

bitbucket = Cloud(
    username=bitbucket_email,
    password=bitbucket_password,
    cloud=True)

bitbucket_app_pw = Cloud(
    username=bitbucket_username,
    password=bitbucket_app_password,
    cloud=True)

Hi @Vishwas

That mean I need to open and use developer account instead of local server.

If the developer account, then how should I do or is it free or payable service?

Is there any way to use local server's experiment first before Cloud for the above assessment(https://atlassian-python-api.readthedocs.io/bitbucket.html#) ?

 

Best regards

Hi @Vishwas ,

This URL https://pypi.org/project/bitbucket-python/ is working with 

 

bitbucket_email = " "
bitbucket_password = " "

client = Client(bitbucket_email, bitbucket_password)

 

However, it is not enough for my use case since I would like to do like this URL https://atlassian-python-api.readthedocs.io/bitbucket.html#

But, I didn't have the proper Python package to install and set the Configuration yet.

Really appreciate your kind help soon.

 

Best regards

Vishwas Rising Star Feb 20, 2022

Hey @Kyaw 

Firstly i would like to understand the hosting you are on, without that i can't suggest.

But in generic let me answer the queries you have.

That mean I need to open and use developer account instead of local server.  --> there is no need to open developer account for this. If you are on bitbucket cloud https://bitbucket.org/ you can generate an app password and use it in the API query.

But I understand that you are in https://bitbucket.org/ this only as mentioned above https://bitbucket.org/mrkyawkyawoo/. So navigate here and create app password https://bitbucket.org/account/settings/app-passwords/

If the developer account, then how should I do or is it free or payable service? --> Bitbucket free plan is there, so no need to pay anything for developer account

Is there any way to use local server's experiment first before Cloud for the above assessment(https://atlassian-python-api.readthedocs.io/bitbucket.html#) ?  ->

Yes, you may have to install a local server of bitbucket datacentre variant to try them out https://www.atlassian.com/software/bitbucket/download/data-center

KB on how to install https://confluence.atlassian.com/bitbucketserver/install-bitbucket-data-center-872139817.html

Lastly 

But, I didn't have the proper Python package to install and set the Configuration yet. -> what type of package are you expecting ?

This pip library pip install atlassian-python-api should be enough for you to use the API mentioned here https://atlassian-python-api.readthedocs.io/bitbucket.html#

 

 

Hi @Vishwas .

 

Thanks for prompt and detailed info.

I will try again first these https://atlassian-python-api.readthedocs.io/bitbucket.html#

However, I am still not getting to use the object instance of bitbucket(initial configuration) as below

 

from atlassian import Jira
from atlassian import Confluence
from atlassian import Bitbucket
from atlassian import ServiceDesk
from atlassian import Xray
from XXXXX import XXXXX -> Import package name ?


bitbucket = XXXX(bitbucket_email, bitbucket_password)
bitbucket.project_list()
bitbucket.get_repo(project_key, repository_slug)
# Delete an existing Code Insights report
bitbucket.delete_code_insights_report(project_key, repository_slug, commit_hash, report_key)


# Decline pull request
bitbucket.decline_pull_request(project_key, repository, pr_id, pr_version
# Object oriented:
    # Get the repository first
    r = cloud.workspaces.get(workspace).repositories.get(repository)

Really appreciate your kind and prompt response.

 

Best regards

Vishwas Rising Star Feb 21, 2022

Hey @Kyaw 

I get it now

Its this line for bitbucket cloud

from atlassian.bitbucket import Cloud

 and this in case of server/dc

from atlassian import Bitbucket

Hi @Vishwas 

Here is 

from atlassian import Bitbucket
Bitbucket -> bitbucket => how can I get this pls ?
How to instantiate like this ?
bitbucket = Bitbucket(
        url='http://localhost:7990',
        username=user_name,
        password=pass_word)
bitbucket.project_list()
Vishwas Rising Star Feb 21, 2022

I don't understand sir :( Really confused here. Are you on server or cloud ?

the part is bitbucket server

bitbucket = Bitbucket(
        url='http://localhost:7990',
        username=user_name,
        password=pass_word)
to do this do we have bitbucket hosted on Virtual Machine ? To test like above we need a on-premise bitbucket application without that we can't.

Good day @Vishwas 

Sorry for my confused questions and I am using currently 

https://bitbucket.org/mrkyawkyawoo/

bitbucket_email = ""
bitbucket_password = ""
from bitbucket.client import Client
client = Client(bitbucket_email, bitbucket_password)
# Get user information
response = client.get_user()
# print(response)
Above these are working well.
I am not sure how to configure using the package below to call
from atlassian import Bitbucket
bitbucket.project_list()
bitbucket.get_repo(project_key, repository_slug)
# Delete an existing Code Insights report
bitbucket.delete_code_insights_report(project_key, repository_slug, commit_hash, report_key)


# Decline pull request
bitbucket.decline_pull_request(project_key, repository, pr_id, pr_version
# Object oriented:
    # Get the repository first
    r = cloud.workspaces.get(workspace).repositories.get(repository)

Hi @Vishwas ,

 

Is it possible to have a short discussion of my use case via any communication channel like zoom, hangout, skype and so on pls ?

If it so how about today or tomorrow to expedite the process pls?

 

Best regards

Vishwas Rising Star Feb 21, 2022

Hey @Kyaw 

Not a problem, we at community are here to suggest and guide on best possible way.

When using cloud API there is no need to use this package 

from atlassian import Bitbucket

I have also not much expertise on this but can guide you on the basic to get you going.

You can send a Zoom or hangout invite.

Hi @Vishwas ,

Thanks for your lots of advice and before sending the zoom pls let me know your time zone with your available time pls.

Vishwas Rising Star Feb 21, 2022

@Kyaw 

I'm at IST time zone. That is +05:30 GMT. You can send me invite around 1:00 PM IST. Is that okay for you. I'm not sure which time zone you are in it could be late for you.

Or else you can send the invite in late evenings here.

Hi @Vishwas ,

How about 8 PM of IST time today pls ?

If fine then pls your email to send the zoom invitation link.

@Vishwas ,

just sent and see you today 8 PM(IST) with your acknowledgement email pls.

Hi @Vishwas 

 

Are you there pls ?

Hi @Vishwas ,

Most of the read API may work Python Programmatically but will try to write something onwards.

Thanks for last late evening catch up and see you today again as usual time if you were fine.

Vishwas Rising Star Feb 22, 2022

Hi @Kyaw 

Sure i would like to join and learn.

Hi @Vishwas

 

I am zoom and are you busy ?

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events