Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API: How to check user or organization name availability?

I can send an HTTP request to the GitHub API to automate creating new or deleting repositories, delete repositories, etc.

For example, I can create a new repository like this:

curl --user "$user" "https://api.github.com/user/repos" -d  {\"name\":\"$repo\"}"

I have been unable to any find documentation on how to create a new GitHub account or check if a user/organization name is available.

like image 729
Jorge Bucaran Avatar asked Mar 11 '15 01:03

Jorge Bucaran


People also ask

How do I find my GitHub organization name?

In the top right corner of GitHub.com, click your profile photo, then click Your organizations.

How do I show organizations on GitHub profile?

In the top-right corner of GitHub Enterprise Server, click your profile photo, then click Enterprise settings. In the enterprise sidebar, click Policies. Under Policies, click Options. Under "Default organization membership visibility", use the drop-down menu, and click Private or Public.

How do I find users on GitHub?

Create an async function getUsers(names) , that gets an array of GitHub logins, fetches the users from GitHub and returns an array of GitHub users. The GitHub url with user information for the given USERNAME is: https://api.github.com/users/USERNAME . There's a test example in the sandbox.


1 Answers

There is no way to create new users using the API. If you wanted to do this automatically, you would have to jump through a lot of hoops, including automatically confirming email addresses and you would probably be violating the TOS. Why would you want to do that?

Checking for usernames is much easier. To do this with the regular GitHub API, use:

curl -w '%{response_code}' 'https://api.github.com/users/<username>'

If it's a 404, the username should be available, assuming it meets all the username requirements (length, characters, etc).

An even easier way is to use what GitHub uses on its registration form:

curl --write-out ' %{http_code}\n' --data "value=$USERNAME" https://github.com/signup_check/username

This prints a little message if the username is unavailable and returns a 403. It returns 200 if it's available.

like image 162
Hut8 Avatar answered Sep 23 '22 15:09

Hut8