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).

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It's the github.com login password instead of $token and the link to create a token is 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.