Issue Summary
The Rest API for retrieving Webhooks is broken when using the limit and start query parameters (start=0&limit=2) to retrieve the desired number of results.
Steps to Reproduce
- Have at least 4 Webhooks configured.
- Use the REST API to retrieve the Webhooks, for example:
curl -H "Authorization: Bearer xxxxx" -X GET https://localhost:8444/b760/rest/api/1.0/projects/LIN/repos/practice_git/webhooks?start=0&limit=2
Expected Results
2 Webhooks should be returned.
{
"size": 2,
"limit": 2,
"isLastPage": false,
"values": [
{
"id": 6,
"name": "danny",
"createdDate": 1617782072303,
"updatedDate": 1617782072303,
"events": [
"repo:refs_changed"
],
"configuration": {
"createdBy": "bitbucket"
},
"url": "http://localhost:8080/bitbucket-scmsource-hook/notify",
"active": true
},
{
"id": 7,
"name": "https://d1f9f469ec5730337b80ff1302c3c739.m.pipedream.net",
"createdDate": 1617782072305,
"updatedDate": 1617782072305,
"events": [
"repo:refs_changed"
],
"configuration": {},
"url": "https://d1f9f469ec5730337b80ff1302c3c739.m.pipedream.net",
"active": true
}
],
"start": 0,
"nextPageStart": 2
}
Actual Results
3 Webhooks are returned as show below:
{
"size": 2,
"limit": 2,
"isLastPage": false,
"values": [
{
"id": 6,
"name": "danny",
"createdDate": 1617780109672,
"updatedDate": 1617780109672,
"events": [
"repo:refs_changed"
],
"configuration": {
"createdBy": "bitbucket"
},
"url": "http://localhost:8080/bitbucket-scmsource-hook/notify",
"active": true
},
{
"id": 7,
"name": "https://d1f9f469ec5730337b80ff1302c3c739.m.pipedream.net",
"createdDate": 1617780109674,
"updatedDate": 1617780109674,
"events": [
"repo:refs_changed"
],
"configuration": {},
"url": "https://d1f9f469ec5730337b80ff1302c3c739.m.pipedream.net",
"active": true
},
{
"id": 9,
"name": "43209a81b9b5694b39daf4d231c44dd76d12f4ef",
"createdDate": 1617780109675,
"updatedDate": 1617780109675,
"events": [
"repo:refs_changed"
],
"configuration": {
"createdBy": "jenkins"
},
"url": "http://localhost:8080/bitbucket-server-webhook/trigger",
"active": true
}
],
"start": 0,
"nextPageStart": 2
}
Workaround
The workaround is adding a "+1" to the nextPageStart when calling the next page. For example,
-- Current API call curl -H "Authorization: Bearer xxxxx" -X GET https://localhost:8444/b760/rest/api/1.0/projects/LIN/repos/practice_git/webhooks?start=0&limit=2 -- Next API call curl -H "Authorization: Bearer xxxxx" -X GET https://localhost:8444/b760/rest/api/1.0/projects/LIN/repos/practice_git/webhooks?start=3&limit=2
However, the lastpage is true only when the page limit is has reached or exceeded the number of Webhooks. For example, if 4 Webhooks are available it behaves like this:
curl -H "Authorization: Bearer xxxxx" -X GET https://localhost:8444/b760/rest/api/1.0/projects/LIN/repos/practice_git/webhooks?start=0&limit=3 -- Output 4 Webhooks with lastpage as false curl -H "Authorization: Bearer xxxxx" -X GET https://localhost:8444/b760/rest/api/1.0/projects/LIN/repos/practice_git/webhooks?start=0&limit=4 -- Output 4 Webhooks with lastpage as true curl -H "Authorization: Bearer xxxxx" -X GET https://localhost:8444/b760/rest/api/1.0/projects/LIN/repos/practice_git/webhooks?start=4&limit=4 -- Output 1 Webhook with lastpage as true
- is blocked by
-
WEBHOOKS-157 Loading...