Branches API Command Not Returning all the Branches

I’m using branches from the API to get my branches. Here’s an example:

https://code.example.com/api/v4/projects/projectID/repository/branches

When I use this command, not all of my branches come back. I’m looking for the default branch, and it’s not among the list, so my code fails. How do I either get the default branch, or get all of the branches so that I can find it?

How do I get the default branch?

If you only wish to lookup the default branch on a project’s repository, the Get single project API call carries a default_branch field in its response:

~> curl -s 'https://gitlab.example.com/api/v4/projects/:ID' | jq -r '.default_branch'
main

I’m using /branches from the API to get my branches
Not all of my branches come back
How do I get all of the branches?

The List repository branches API, like other collection-returning API calls, uses pagination and limits each response to a number of maximum items. Follow the pagination instructions to retrieve the full set of results iteratively.