Skip to content

Instantly share code, notes, and snippets.

@gene1wood
Last active December 2, 2022 11:08
Show Gist options
  • Save gene1wood/24d828b592caea98ae5dafcd4dd8e60d to your computer and use it in GitHub Desktop.
Save gene1wood/24d828b592caea98ae5dafcd4dd8e60d to your computer and use it in GitHub Desktop.
How to edit or modify a GitHub user's permissions on a repository through the API

The GitHub API is inconsistent for this endpoint. Normally to edit or modify a resource, the REST API uses the PATCH verb.

For the https://developer.github.com/v3/repos/collaborators/ endpoint however, to edit or modify a user's permissions, there is no PATCH verb. Instead you must make a PUT call defining the new permissions.

The documentation confusingly describes this as "Add user as a collaborator" when the user you're modifying already is a collaborator, you just want to change their permissions.

Here is an example call to change a user with push permissions to pull permissions

curl -v -H "Authorization: token TOKEN" https://api.github.com/repos/OWNER/REPO/collaborators/COLLABORATOR -X PUT -d '{"permission":"pull"}'

I learned this from a response from GitHub support.

@berniedurfee
Copy link

Boom, thank you!! This saved me much head scratching. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment