# /api/repos/{user}/{repo}/builds/latest doesn't return expected results

**URL:** <https://drone.discourse.group/t/api-repos-user-repo-builds-latest-doesnt-return-expected-results/7561>\
**Category:** Drone Support\
**Created:** [August 28, 2019, 6:20pm UTC](https://drone.discourse.group/t/api-repos-user-repo-builds-latest-doesnt-return-expected-results/7561 "2019-08-28T18:20:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bachya](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bachya/32/6040_2.png) [@bachya](https://drone.discourse.group/u/bachya)\
**Post date:** [August 28, 2019, 6:20pm UTC](https://drone.discourse.group/t/api-repos-user-repo-builds-latest-doesnt-return-expected-results/7561/1 "2019-08-28T18:20:38Z")

</div>

I notice that `/api/repos/{user}/{repo}/builds` returns _all_ builds for that repo, regardless of branch (as long as the branch is a target in `.drone.yml`, of course).

However, when I attempt to get the latest build via `/api/repos/{user}/{repo}/builds/latest`, I notice that the API returns the latest build _from `master` no matter what_.

I deduced that I can add a `branch` query parameter, but shouldn’t `/api/repos/{user}/{repo}/builds/latest` return the latest build, regardless of which branch it was on?

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [August 28, 2019, 6:27pm UTC](https://drone.discourse.group/t/api-repos-user-repo-builds-latest-doesnt-return-expected-results/7561/2 "2019-08-28T18:27:16Z")

</div>

the endpoint returns the latest build for the default branch (similar to how badges work) and is therefore behaving as designed.

---

<div class="post-metadata">

**Author:** ![bachya](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bachya/32/6040_2.png) [@bachya](https://drone.discourse.group/u/bachya)\
**Post date:** [August 28, 2019, 6:43pm UTC](https://drone.discourse.group/t/api-repos-user-repo-builds-latest-doesnt-return-expected-results/7561/3 "2019-08-28T18:43:51Z")

</div>

Got it; thanks for the clarification. Is there a way to do what I’m asking – get the latest build from any branch – without getting all builds and cutting from the top?

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [August 28, 2019, 7:23pm UTC](https://drone.discourse.group/t/api-repos-user-repo-builds-latest-doesnt-return-expected-results/7561/4 "2019-08-28T19:23:26Z")

</div>

using `/api/repos/{user}/{repo}/builds?per_page=1` should work.

---

<div class="post-metadata">

**Author:** ![bachya](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bachya/32/6040_2.png) [@bachya](https://drone.discourse.group/u/bachya)\
**Post date:** [August 28, 2019, 7:54pm UTC](https://drone.discourse.group/t/api-repos-user-repo-builds-latest-doesnt-return-expected-results/7561/5 "2019-08-28T19:54:05Z")

</div>

Confirmed. Thank you!
