Pending state not returned when user requests to join team

Hi, I’m using Octokit to request the current membership status of a user in an organisation team using

const response = await octokit.teams.getMembershipForUserInOrg({
      org,
      team_slug,
      username,
    });

Tried using these endpoints:

When that user is in the team it returns a 200 with the state as active and returns a 404 when the user isn’t in the team. However, according to the docs, it should return a 200 when they are in the pending state too, When that user clicks the “Request to join team” button on GitHub it doesn’t seem to set them into a pending state and still returns 404.

Does the pending state only apply for invites? and doesn’t work when requesting to join?

Hi, hi @AlfieBrooks :wave:

I went ahead and reproduced this by:

  • Having an Org user request to join my Team
  • Inviting a user not in the Org to join my Team (users in an Org simply get added to a Team, and there is no invitation/pending status)

Between each step, I tried each endpoint:

  • Get team membership for a user
  • List pending team invites

What I found, is that when the user requested access to the Team

/orgs/{org}/teams/{team_slug}/memberships/{username} returns a 404:

{
    "message": "Not Found",
    "documentation_url": "https://docs.github.com/rest/reference/teams#get-team-membership-for-a-user"
}

…and /orgs/{org}/teams/{team_slug}/invitations endpoint returns:

…an empty array:

➜  ~ curl -L -X GET 'https://api.github.com/orgs/{org}/teams/{team_name}/invitations' \
-H 'Authorization: bearer KEY' \
-H 'Accept: application/vnd.github.v3+json'
[
]

When the invitation was sent to a user not already within the Org to join the Team

/orgs/{org}/teams/{team_slug}/memberships/{username} returns:

{
    "state": "pending",
    "role": "member",
    "url": "https://api.github.com/organizations/{org_id}/team/{team_id}/memberships/{username}"
}

/orgs/{org}/teams/{team_slug}/invitations returns:

[
    {
        "id": {id},
        "node_id": "{node_ID}",
        "login": "username",
        "email": null,
        "role": "direct_member",
        "created_at": "2020-09-28T12:04:22.000-07:00",
        "inviter": {
            "login": "nethgato",
            "id": {id},
            "node_id": "{node_id}",
            "avatar_url": "{avatar_url}",
            "gravatar_id": "",
            "url": "https://api.github.com/users/nethgato",
            "html_url": "https://github.com/nethgato",
            "followers_url": "https://api.github.com/users/nethgato/followers",
            "following_url": "https://api.github.com/users/nethgato/following{/other_user}",
            "gists_url": "https://api.github.com/users/nethgato/gists{/gist_id}",
            "starred_url": "https://api.github.com/users/nethgato/starred{/owner}{/repo}",
            "subscriptions_url": "https://api.github.com/users/nethgato/subscriptions",
            "organizations_url": "https://api.github.com/users/nethgato/orgs",
            "repos_url": "https://api.github.com/users/nethgato/repos",
            "events_url": "https://api.github.com/users/nethgato/events{/privacy}",
            "received_events_url": "https://api.github.com/users/nethgato/received_events",
            "type": "User",
            "site_admin": true
        },
        "team_count": 1,
        "invitation_teams_url": "https://api.github.com/organizations/{org_id}/invitations/{invite_id}/teams"
    }
]

So to your question:

Does the pending state only apply for invites? and doesn’t work when requesting to join?

That really does seem to be what’s happening, but it’s not clear that this is expected behavior. Now that I’ve documented these steps here, I’m going to followup with our team to find out if we’re bumping up against unexpected behavior, or perhaps there was something done incorrectly in my reproduction steps.

Thank you for your patience in the meantime! :bow:

Hi again @AlfieBrooks o/

How are you going? I just wanted to followup here since I did get in touch with our teams responsible for maintenance of those endpoints and do have some clarification to add to my post above.

When a user has a pending invitation to join a team, we consider their membership to be pending. When a user has requested to join a team, we consider them to have an inactive membership, so that’s why we see the 404 and empty array response.

We don’t necessarily want to treat a membership request to be a pending membership, as users could essentially request to join any number of teams without any guarantee that their requests would be accepted.

So from that, I think there may be some pending cleanup that we could do, here:

…where:

Response if user has a pending membership with team.

…could be a bit ambiguous.

Curious to know what you think, but also want to thank you for elevating this and hope that the verification of expected behavior is valuable to you!

Let us know. :bow:

1 Like

Hi @nethgato,

Thanks for the response! Yeah, your findings are exactly what I was doing to reproduce this issue. It wasn’t clear for me originally that the pending state was only when a user is invited to a team and not for when requesting to join a team.

That’s understandable that you wouldn’t want to return a pending state when they request if there are thousands of requests to a team. Thank you for confirming that for me!

As you also mentioned, it would be good to get the docs updated to explain what counts as a pending state for a user in a team (Only having been invited to a team).

Thanks again,
Alfie

1 Like

Hey @AlfieBrooks cheers!

So for the docs update, there’s a couple things/options. One, I can simply open an internal issue with our docs team to suggest an update. Two, a submission from you (or anyone else reading with similar requests) via our feedback form:

I’m happy for us to do either, or both! If you feel there is unclear language, both is probably best. If you have a preference for me submitting that directly, happy to do that, too!

LMK what you think :bow: