Take the following Github URL: https://github.com/google
How can I determine whether google
is a user or an organization?
I need to know to this for querying Github's graphql API in the correct way.
If you have the login (username) of the user/group, you can use organization
& user
to search respectively an organization & a user and check which of the 2 fields is not null
:
{
org: organization(login: "google") {
name
members {
totalCount
}
}
user: user(login: "google") {
name
login
}
}
which gives :
{
"data": {
"org": {
"name": "Google",
"members": {
"totalCount": 1677
}
},
"user": null
}
}
or using a variable for login
input, try it in the explorer
For the Rest API v3, it's much simpler since it doesn't distinguish the user from the organization : https://developer.github.com/v3/users :
curl -s 'https://api.github.com/users/google' | jq -r '.type'
Organization
curl -s 'https://api.github.com/users/torvalds' | jq -r '.type'
User