5

When I curl the rest api, I get back an empty response but I know that there are pull-requests open.

What is the setting in bitbucket stash that allows anyone to view/read pull-requests without being authenticated?

curl -X GET https://bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests

response:

{
    "size": 0,
    "limit": 25,
    "isLastPage": true,
    "values": [],
    "start": 0
}
Jon Erickson
  • 112,242
  • 44
  • 136
  • 174

5 Answers5

3

Try

curl -X GET https://bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests?state=ALL

You can find more options for this specific API call at https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm140236731714560

fcdt
  • 2,371
  • 5
  • 14
  • 26
  • this works but requires authentication. can't seem to figure out how to make read access public for pull requests in order to bypass this. – Jon Erickson Nov 01 '17 at 16:21
1

This worked for me:

curl -D- -u user:password -X GET -H "Content-Type: application/json" -X GET https://bitbucket.com/rest/api/1.0/projects/ONEP/repos/oneplanner/pull-requests?state=OPEN
fcdt
  • 2,371
  • 5
  • 14
  • 26
0

To check status to particular PR:

curl -X GET https://bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests/{pr-id}
fcdt
  • 2,371
  • 5
  • 14
  • 26
Suhaib
  • 11
  • 1
0

DOC https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html#idm8287391664 Paged APIs

Bitbucket uses paging to conserve server resources and limit response size for resources that return potentially large collections of items. A request to a paged API will result in a values array wrapped in a JSON object with some paging metadata, like this:

{
    "size": 3,
    "limit": 3,
    "isLastPage": false,
    "values": [
        { /* result 0 */ },
        { /* result 1 */ },
        { /* result 2 */ }
    ],
    "start": 0,
    "filter": null,
    "nextPageStart": 3
}

Clients can use the limit and start query parameters to retrieve the desired number of results.

The limit parameter indicates how many results to return per page. Most APIs default to returning 25 if the limit is left unspecified. This number can be increased, but note that a resource-specific hard limit will apply. These hard limits can be configured by server administrators, so it's always best practice to check the limit attribute on the response to see what limit has been applied. The request to get a larger page should look like this:

http://host:port/context/rest/api-name/api-version/path/to/resource?limit={desired size of page}

For example:

https://stash.atlassian.com/rest/api/1.0/projects/JIRA/repos/jira/commits?limit=1000

The start parameter indicates which item should be used as the first item in the page of results. All paged responses contain an isLastPage attribute indicating whether another page of items exists.

Important: If more than one page exists (i.e. the response contains "isLastPage": false), the response object will also contain a nextPageStart attribute which must be used by the client as the start parameter on the next request. Identifiers of adjacent objects in a page may not be contiguous, so the start of the next page is not necessarily the start of the last page plus the last page's size. A client should always use nextPageStart to avoid unexpected results from a paged API. The request to get a subsequent page should look like this:

http://host:port/context/rest/api-name/api-version/path/to/resource?start={nextPageStart from previous response}

For example:

https://stash.atlassian.com/rest/api/1.0/projects/JIRA/repos/jira/commits?start=25
0

Currently the api 1.0 is deprecated. I know that the question specifies Bitbucket api 1.0, but this would be useful for future developers to find this question.

I would suggest reading the REST API documentation here and set an authorisation token: https://developer.atlassian.com/cloud/bitbucket/rest/intro/

https://support.atlassian.com/bitbucket-cloud/docs/create-a-repository-access-token/

Finally use the token like this:

curl -X GET -H "Authorization: Bearer <Token>" https://api.bitbucket.org/2.0/repositories/{project name}

The response will give you the sub directories that you have access to. To access the repository pull-requests it can be done like such:

curl -X GET -H "Authorization: Bearer <Token>" https://api.bitbucket.org/2.0/repositories/{project}/<repository>/pullrequests
Kikadass
  • 314
  • 1
  • 3
  • 14