Ricardo Augusto
Ricardo Augusto

Reputation: 558

github api - create repo

I'm trying to create a repo using Github API, but it always return this JSON:

{"message":"Not Found"}

But this error appears only when I try to create using OAuth access token in request header, if I use username and password, API create the repo and return a successful message.

Anyone had problems with this API endpoint?

Upvotes: 4

Views: 4765

Answers (5)

Peterino
Peterino

Reputation: 16677

As of today, the GitHub v3 API documentation explicitly states:

Create

Create a new repository for the authenticated user. (Currently not enabled for Integrations)

EDIT: The "not enabled for Integrations" means, if you get your OAuth token via one of your OAuth apps (which is an "integration") the GitHub API will refuse to create a repository with that function.

However, if you use some other access token (e.g. a personal access token you add yourself, see below) then the GitHub API will happily create a repository for you with the very same API call.

curl -u your_username -d '{"scopes":["repo"], "note":"Description of personal token"}' https://api.github.com/authorizations

That's the reason why the solution presented by Ian Warner works. The solution with PyGithub will suffer the same limitation. Only the token makes the difference!

EDIT: Not entirely true: With OAuth you can specify the scope to attach specific permissions to your OAuth token when authenticating (OAuth app flow). For creating repositories you need to have the 'repo' scope. (See also: Github v3 API - create a REPO)

Upvotes: 0

Harshdeep Singh
Harshdeep Singh

Reputation: 337

You can create a new repository using the Python library, PyGithub.

from github import Github
g = Github("your username", "your password")
g = Github("your token")  # safer alternative, if you have an access token
u = g.get_user()
repo = u.create_repo("name-of-your-repo")

This should solve your problem.

Upvotes: 4

Manish Verma
Manish Verma

Reputation: 539

I do not know what technology you are using. But just in case of iOS, you can use this demo app which describes 3 simple ways to interact with the GitHub API.

Note: This demo app provide only few selected functionality.

GitHub-Interaction

Hope this helps!!

Upvotes: 0

Ian Warner
Ian Warner

Reputation: 1068

I had a different message come up with this

curl -i -d '{"name":"NAME"}' https://api.github.com/orgs/:ORG/repos?access_token=XXX

{
  "message": "Must be an owner or admin of Organization."
}

But still not sure why I cannot create either

Ok

This worked for me

Create Auth Token

curl -u 'iwarner' -d '{"scopes":["repo"],"note":":NAME"}' https://api.github.com/authorizations

Create Repo - Need to contain "Authorization: token"

curl -i -H 'Authorization: token TOKENHERE' -d '{"name":":NAME"}' https://api.github.com/user/repos

Upvotes: 1

c00kiemon5ter
c00kiemon5ter

Reputation: 17594

This works, just tried it.

curl -F 'login=c00kiemon5ter' -F 'token=s3cr3t' https://github.com/api/v2/json/repos/create -F 'name=testapi' -F 'public=0'

Are we talking about API v2 or v3 ?

Upvotes: 0

Related Questions