Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create repository in github through github API?

I am trying to use github api to create repositories under a particular organization. I was looking at this site which talks about how to create repositories under a particular organization.

Create a new repository in this organization. The authenticated user must be a member of the specified organization.
POST /orgs/:org/repos

Now I am not able to understand what will be my full URL that I need to use to create the repository under a particular organization? I have my username and password which I can use to create the repository under an organization through https url.

My github instance url is like this - https://github.host.com

And I want my repository to be like this after getting created -

https://github.host.com/Database/ClientService

What will be my curl command look like to create the repository under an organization?

like image 252
john Avatar asked Feb 07 '15 18:02

john


People also ask

How do I create a repo in GitHub API?

Go to Settings -> Developer Settings -> Personal Access Token Under OAuth Apps. Now, Generate a New Access token with Required privileges enabled. Ignore This if you already have one.

How do I get my GitHub API repository?

You can use the github api for this. Hitting https://api.github.com/users/USERNAME/repos will list public repositories for the user USERNAME.

Can I create API in GitHub?

Log in to your GitHub account and click on Settings under your profile. Go to Developer Settings ->Personal Access Tokens. Generate a new token. Add a name and select the scope for the API access and click on Create Token.


2 Answers

Go to Settings -> Developer Settings -> Personal Access Token Under OAuth Apps. Now, Generate a New Access token with Required privileges enabled. Ignore This if you already have one.

User Account:

Replace ACCESS_TOKEN with Token and NEW_REPO_NAME with your New Repository Name in the command below:

curl -H "Authorization: token ACCESS_TOKEN" --data '{"name":"NEW_REPO_NAME"}' https://api.github.com/user/repos

Organization:

curl -H "Authorization: token ACCESS_TOKEN" --data '{"name":"NEW_REPO_NAME"}' https://api.github.com/orgs/ORGANIZATION_NAME/repos
like image 176
Teja Kummarikuntla Avatar answered Oct 13 '22 08:10

Teja Kummarikuntla


Step 1: Create a personal access token and use it in place of password

Step 2: On command line use the given API as a POST request

https://api.github.com/orgs/<organisation_name>/repos?access_token=<generated token>

or

https://api.github.com/user/<username>/repos?access_token=<generated token>

In body, pass this as a payload:

{
  "name": "<Repo Name>",
  "description": "<Some message>",
  "homepage": "https://github.com",
  "private": false,
}

You can pass other details.
For more details: click here

like image 15
Jitendra Kumar Avatar answered Oct 13 '22 06:10

Jitendra Kumar