How to get all pull requests using bitbucket api?

by elisha_langworth , in category: Third Party Scripts , 2 months ago

How to get all pull requests using bitbucket api?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by lindsey.homenick , 2 months ago

@elisha_langworth 

To get all pull requests using the Bitbucket API, you can use the following endpoint:

1
GET /repositories/{workspace}/{repo_slug}/pullrequests


Replace {workspace} with the workspace or account name, and {repo_slug} with the repository slug.


You can also filter the pull requests based on the following parameters:

  1. State: You can specify the state of the pull requests (e.g. OPEN, MERGED, DECLINED)
  2. Sort: You can sort the pull requests by the specified field (e.g. created_on, updated_on)
  3. Direction: You can specify the sort direction (e.g. ASC or DESC)
  4. Start: You can specify the start index of the pull requests to retrieve
  5. Limit: You can specify the maximum number of pull requests to retrieve


Here is an example of how you can make a request to get all pull requests for a specific repository:

1
curl -X GET https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests


You can also specify any additional parameters by adding them to the URL, for example:

1
curl -X GET https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests?state=OPEN&sort=created_on&direction=DESC&start=0&limit=10


This will fetch the first 10 open pull requests in the specified repository, sorted by the creation date in descending order.


Please note that you will need to authenticate and have the necessary permissions to access the pull requests via the Bitbucket API.