Creating a new repo using the API?
API (v4) Creating New Project Within Group
API: create project from template
git - Create a repo in GitLab using CLI - Stack Overflow
For anyone looking for the direct command:
STEP 1:
Navigate as below and identify the group ID from GUI:
Admin Area -> Groups -> GroupName

STEP 2:
Construct the command with two parameters viz., name, namespace_id
curl --header "PRIVATE-TOKEN: <myprivatetoken>" -X POST "https://gitlab.com/api/v4/projects?name=myexpectedrepo&namespace_id=38"
Both users and groups are considered "namespaces" as far as the Gitlab API is concerned, so you can use either a group ID or a username in the namespace_id field. You can see this in use by getting a single namespace with either a Group ID (that you can see in the /groups API call, or from a Group's "profile" page) or a username:
# this will show the namespace details of the Group with ID 54
curl --header "PRIVATE-TOKEN: ${TOKEN}" "https://gitlab.com/api/v4/namespaces/54
# this will show the namespace details of the User with username my-username
curl --header "PRIVATE-TOKEN: ${TOKEN}" "https://gitlab.com/api/v4/namespace/my-username
Hi all, are there any resources with examples that allow creating a repo with the GitLab API? What I'm trying to do is create the remote repo from the command line, is this possible?
Any tips would appreciated. Thank you!
gitlab-cli is no longer maintained, the author references the Gitlab module to be used instead - it also includes a CLI tool.
For your specific request - namely creating a project on the command line, use the following command:
gitlab create_project "YOUR_PROJECT_NAME" "{namespace_id: 'YOUR_NUMERIC_GROUP_ID'}"
Be sure to use the option namespace_id and not group_id! If you are not sure what your GROUP_ID is, you can use
gitlab groups | grep YOUR_GROUP_NAME
to find out.
The parameters for each command can be inferred from the API documentation. Any non-scalar valued parameter has to be encoded in an inline YAML syntax (as above).
Since you just wanted to create a repo, there is no need of third party apps. You can directly send a post request to gitlab API which will create repo.
Go to account tab in your profile, you will find a private token. Copy that.
Now open terminal and run this command with private token (say foo) and your repo name (say bar).
curl -H "Content-Type:application/json" https://gitlab.com/api/v4/projects?private_token=foo -d "{ \"name\": \"bar\" }"
For convenience, you can create a shell script, if you don't want to run this command every time.
#!/bin/sh
curl -H "Content-Type:application/json" https://gitlab.com/api/v4/projects?private_token=foo -d "{ \"name\": \"$1\" }"
Save this to a file gcr.sh and make it executable using chmod +x gcr.sh.
Now to create a repo name bar, run
$ ./gcr.sh bar