[BUG]: Team Membership API calls fail with Octokit high-level methods but work with direct requests #510
Labels
Status: Triage
This is being looked at and prioritized
Type: Bug
Something isn't working as documented
What happened?
Summary
When using Octokit's high-level methods (specifically., octokit.teams.addOrUpdateMembershipForUserInOrg()), I consistently receive a 403 permission error despite having organization owner permissions. However, identical requests using curl or octokit.request() work perfectly.
Steps to Reproduce
await octokit.teams.addOrUpdateMembershipForUserInOrg({ org: 'OrganizationName', team_slug: 'team-name', username: 'github-username', role: 'member' })
This should be possible according to the docs: https://octokit.github.io/rest.js/v21/#teams-add-or-update-membership-for-user-in-org
I can confirm that
Error Message
[HttpError]: You must be an organization owner or team maintainer to add a team membership. - https://docs.github.com/rest/teams/members#add-or-update-team-membership-for-a-user status: 403
Expected Behavior
The high-level method should successfully add the user to the team, just like the following working alternatives do:
Working direct API call with curl:
curl -X PUT \ -H "Authorization: token GITHUB_TOKEN" \ -H "Accept: application/vnd.github.v3+json" \ -d '{"role":"member"}' \ https://api.github.com/orgs/OrganizationName/teams/team-name/memberships/github-username
Working request with Octokit's request method:
await octokit.request('PUT /orgs/{org}/teams/{team_slug}/memberships/{username}', { org: 'OrganizationName', team_slug: 'team-name', username: 'github-username', role: 'member', headers: { 'X-GitHub-Api-Version': '2022-11-28' } })
Versions
Octokit version: 21.0.0
Octokit core: 6.1.2
Node: 20.18.3
Os: Linux
Relevant log output
Code of Conduct
The text was updated successfully, but these errors were encountered: