Branch protection API returning 404

I followed the documentation found here:

I’m running the following curl command and receiving a 404

curl \
  -H "Accept: application/vnd.github.v3+json" \

I’ve also tried to run this using an API token on one of my private branches which is also returning a 404.

By private branch do you mean the branch is on a private repository? Branch protection rules are only for public repositories or private if you have pro.

Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.

1 Like

We are on a GitHub Enterprise - Software Inc. · GitHub

With that in mind, shouldn’t I be able to use one of my admin tokens to get this information?

1 Like

If your account has access to branch protection rules on the web interface in the organization it should work. Maybe there’s something wrong with the branch name? The token probably isn’t the issue since it didn’t throw an unauthorized error.

1 Like

That’s good to know, the branch is our develop branch so I don’t see an issue with the naming?

1 Like

Does the token have the full repo scope? It might be required if it’s on a private repo. Other than that I can’t really see why it would throw a 404.

1 Like

I gave our bot all of the permissions, I have it setup through a GitHub action (one of GitHub’s actions I believe)

  - name: Get existing branch protection
    id: get_branch_protection
    uses: octokit/request-action@v2.0.24
      route: GET /repos/digital-ai/dot-components/branches/develop/protection
      mediaType: |
        format: application/json
1 Like

Is the bot a member of that organization?

1 Like

Yes, and it has write access on it. I also set up the bot account to bypass pull request requirements.

1 Like

I just made the bot an admin on the repo in question and now it seems to be working!

Now the error I’m getting is…

Warning: Unexpected input(s) 'required_status_checks', 'enforce_admins', 'required_conversation_resolution', 'required_pull_request_reviews', valid inputs are ['route', 'mediaType']
Run octokit/request-action@v2.0.24
PUT /repos/digital-ai/dot-components/branches/develop/protection
> mediaType: [object Object]
> required_status_checks: null
> enforce_admins: null
> required_conversation_resolution: null
> required_pull_request_reviews: null
Error: Invalid request.

"restrictions" wasn't supplied.
1 Like
restrictions object or nullable body Required. Restrict who can push to the protected branch. User, app, and team restrictions are only available for organization-owned repositories. Set to null to disable.

Branches - GitHub Docs

1 Like

Fantastic, that was the final thing that got it working! You’re the best <3