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

Next challenges

Recent achievements


  • Give kudos
  • My kudos


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Programmatically create Pull Request on BitBucket repo using REST API? Edited

Update: Well, I was running this in a Bash script, but I wanted to see what error code I was getting, and now I can see I am getting a "401 Unauthorized". I am using my username and I created Personal Access Token with `admin` access bitbucket, so I should be able to create a PR right? I can do this through the web UI on the same repo?

I am running a bash script to create a pull request on Bitbucket. I already am programmatically cloning the repo, editing a file, doing a git add/commit, now I just need to use CURL to make the PR. It seems the bitbucket API exposes a endpoint to do this using a POST request:

Here's how my repo looks on Bitbucket, I blocked out the real names, but the left format the same (the first name is the Project name, "REACTOR2.0", while I believe the second name is the repository name, "dat-repo"):


I am trying many different variations, and am checking the remote bitbucket server for a new pull request, but I see _nothing_.

I'm certain my "title" and "branch" are correct. My only question is about the URL; I am inputting my username from bitbucket, if you go to "Manage Account" then "name", that is the field I'm using for the "my-username" part of the URL, and I'm adding the repository name for the "my-repository" part. However, I need to note that this is a repository on bitbucket nested inside a Project called "REACTOR2.0", so I wasn't sure if the project name needed to be specified in the URL somewhere.

Has anyone been successful with this API? I looked on google, but many questions were using the old 1.0 API and don't apply or people were doing GET request do simply get a list of pull requests....


1 answer

0 votes

Hi Al,

I checked in our system the Bitbucket Cloud account linked with the email you use in this Community account, and I see that it doesn't own any repositories or have access to other repositories.

Do you perhaps have another Bitbucket Cloud account with a different email?

To answer your question: the "my-username" field in the URL should be the workspace ID of the workspace that owns the repo. While you are logged in to the account that has access to this repo, select your avatar (bottom left corner) > All workspaces. Then select the workspace that owns this repo. After you do, you will find the workspace ID in the URL, which will have the format This workspace-id should be in the place of "my-username" in the URL.

You don't need to specify the project for this API call.

I would recommend:
1. Checking that you have generated an app password for the Bitbucket Cloud account that has access to this repo
2. Make sure that the "my-username" field has the value of the workspace ID, as per my instructions above

An example call that works is the following:

curl -L -X POST --user username:password --header 'Content-Type: application/json' --data '{"title": "My Title","source": {"branch": {"name": "feature-branch"}}, "destination": {"branch": {"name": "master"}}}'

username is the username of your Bitbucket account
password is the password of your Bitbucket account or an app-password
workspace-id is as I explained above
repo-slug is the repo-slug for the repo
in the data, replace the values for title, source and destination branch

Please feel free to let me know how it goes.

Kind regards,

Thank you, yes it was a bitbucket Server account and I was able to figure out how to create the automated PR by another atlassian representative.


Thank you!

Like Theodora Boudale likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,912 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you