Github API to accept organization invitation by member user

Is there github API to accept invitation? I am trying to update pending membership through PATCH /user/memberships/orgs/{org} but it throws the following error message -

{
“message”: “You do not have access to this organization membership.”,
“documentation_url”: “https://developer.github.com/v3/orgs/members/#get-your-organization-membership
}

I know I can accept invitation via email but I am looking for available github API.

Please help!

1 Like

HI @phoenix303,

Thanks for being here! That message does point to a permissions issue, do you a token from the organization’s owner.

Only the user themselves can accept the invitation, the org owner cannot accept it on their behalf.

If you’re authenticated as a legacy OAuth app as the user with the ‘org:write’ scope, you can call this API with the user’s token to have them accept their own invite: https://developer.github.com/v3/orgs/members/#edit-your-organization-membership

The app itself also needs to be authorized with Third-party access on the organization.

That said, I have a newer GitHub App where I am trying to do the thing, and it isn’t working, so there may be other lingering issues.

This was fixed.

GitHub Apps can now use the user-to-server APIs to update org membership and accept org invites.

Thank you to the API team.