0

According to the general instruction to the github.com API and the explanation of the create command

curl -u "krichter722" https://api.github.com # works (returns JSON response)
curl -d '{"name":"test"}' https://api.github.com/user/repos/

should work and create a repository, but the second command fails with

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
}

I found Using `curl` to create a repo on GitHub.com with two-factor authentication which resolves an issue caused by missing parts in the request for two-factor authentication.

Other questions, like "Bad Credentials" when attempting to create a GitHub repo through the CLI using curl, indicate that the URL is correct (the creation fails due to bad credentials according to error message in this case).

Community
  • 1
  • 1
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177

1 Answers1

2

You can do it as follows:-

curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'

You can find personal access token in Github Settings -> Application, replace username with your username and repo_name with repository name.

Note:- You might need to create personal access token if you haven't used it earlier.

hspandher
  • 15,934
  • 2
  • 32
  • 45
  • It's the github.com login password instead of `$token` and the link to create a token is https://github.com/settings/tokens. The docs read like one needs to authenticate first and then request the API URL, but the trick is to invoke `curl` with both `-u` and `-d` options. Confirmed to work with `python`'s `request` modules as well. – Kalle Richter Aug 27 '15 at 16:54