Popinjoy
Popinjoy

Reputation: 23

Why Github api is not giving only protected branches?

Given below is the api url. Not sure if I am passing the boolean value wrong. I would like to get only the protected branches but its giving me all branches.

"https://github.com/api/v3/repos/kpopi/Demo/branches?" + URLEncoder.encode("protected=true", "UTF-8");

Thanks

Above url works after removing the urlencoding. But when I tried on a repo of an org below is what I got.

https://github.com/api/v3/repos/Pilliance/Dhudhu/branches?protected=true

Server:GitHub.com
Date:Thu, 28 Feb 2019 10:26:34 GMT
Content-Type:application/json; charset=utf-8
Transfer-Encoding:chunked
Status:404 Not Found
X-GitHub-Enterprise-Version:2.15.3
X-GitHub-Media-Type:github.v3; format=json
Access-Control-Expose-Headers:ETag, Link, Retry-After, X-GitHub-OTP, X- 
RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, 
X-Accepted-OAuth-Scopes, 
X-Runtime-rack:0.027308
{
 "content": {
 "message": "Not Found",
 "documentation_url": 
 "https://developer.github.com/enterprise/2.15/v3/repos/branches/#list-branches"
 }
}

Yet the below url works

https://github.com/api/v3/repos/Pilliance/Dhudhu/branches

Upvotes: 0

Views: 777

Answers (2)

Parithiban
Parithiban

Reputation: 1656

If you look at the branch api the protected is just a query parameter it need to be added with the API URL

https://api.github.com/repos/octocat/hello-world/branches?protected=true. This will only list the protected branches.

In order to view the protected branch, you should be the repository owner or you should have admin permission for that repository. Try checking you can access the settings tab of that repo.

https://help.github.com/en/articles/about-protected-branches

Upvotes: 0

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230336

Not sure if I am passing the boolean value wrong.

Yes, you are. You don't need the url-encoding here. The problem is that the equal sign stopped denoting a key-value pair (because of encoding).

Upvotes: 1

Related Questions