Skip to main content

Curl Bitbucket Pull Request

·121 words·1 min
O11y | Cloud
Author
O11y | Cloud
Site Reliability Engineer
Table of Contents

I needed a way to programmatically create Bitbucket Pull Request. Here how to do it:

Create API Token
#

In Bitbucket Repo, go to Repository Settings -> Security -> Access tokens and create new token with pull request write (and read) rights.

Use it to create Pull Request
#

git checkout main
git pull origin main
git checkout feature/test-pull-request

# Make your changes

git add .
git commit -m "Test pull request"
git push -u origin feature/test-pull-request

Now use curl to make POST Bitbucket API:

#! /bin/bash
curl --request POST \
  --url 'https://api.bitbucket.org/2.0/repositories/<workspace>/<repo>/pullrequests' \
  --header 'Authorization: Bearer YOUR_API_TOKEN' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
	"title": "My Title",
	"source": {
		"branch": {
			"name": "feature/test-pull-request"
		}
	}
}'