Using Bitbucket REST API to get list of merged pull requests for a specific source and destination branches.
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
Applying a filter to pull request API helps us retrieve the list of merged pull requests for a specific source and destination branches.
Solution
API to be used:
1
curl -s -u <USERNAME>:<APP_PASSWORD> "https://api.bitbucket.org/2.0/repositories/<WORKSPACE_ID>/<REPO_SLUG>/pullrequests?q=destination.branch.name+%3D+%22<dst_branch>%22&source.branch.name+%3D+%22<src_branch>%22&fields=values.id,values.state"
Variables to be replaced by:
USERNAME: Bitbucket username APP_PASSWORD:App password - Atlassian Document WORKSPACE_ID: Name of the workspace REPO_SLUG: Name of the repository
Source: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-group-pullrequests Reference: API filtering - Atlassian Documentation
Example:
Sample Query:
1
curl -s -u lava:ATBB*********** "https://api.bitbucket.org/2.0/repositories/testwork/testrepo/pullrequests?q=destination.branch.name+%3D+%22dev%22&source.branch.name+%3D+%22master%22&fields=values.id,values.state"
Output:
1
2
3
{"values": [
{"id": 1, "state": "MERGED"}
]}%
Updated on March 10, 2025
Was this helpful?
Still need help?
The Atlassian Community is here for you.