Create a new project in a group using API

The message seems a little cryptic, but the is not valid answer explains it.

namespace_id is the id of the namespace, where namespace your username or an organization you can create repos to. When you first create a repo you are presented with a json object like so:

{
   "archived" : false,
   "merge_requests_enabled" : true,
   "path" : "foobartest3",
   "default_branch" : null,
   "namespace" : {
      "owner_id" : 3585,
      "updated_at" : "2013-03-21T05:40:35.000Z",
      "membership_lock" : false,
      "path" : "axil",
      "id" : 3467,
      "created_at" : "2013-03-21T05:40:35.000Z",
      "avatar" : null,
      "description" : "",
      "name" : "axil"
   },
   "wiki_enabled" : true,
   "ssh_url_to_repo" : "git@gitlab.com:axil/foobartest3.git",
   "tag_list" : [],
   "http_url_to_repo" : "https://gitlab.com/axil/foobartest3.git",
   "path_with_namespace" : "axil/foobartest3",
   "id" : 416441,
   "created_at" : "2015-08-19T22:10:41.503Z",
   "name_with_namespace" : "Achilleas Pipinellis / foobartest3",
   "description" : null,
   "name" : "foobartest3",
   "web_url" : "https://gitlab.com/axil/foobartest3",
   "public" : false,
   "snippets_enabled" : false,
   "avatar_url" : null,
   "forks_count" : 0,
   "creator_id" : 3585,
   "owner" : {
      "username" : "axil",
      "avatar_url" : "https://gitlab.com/uploads/user/avatar/3585/corto-maltese-rect.jpg",
      "name" : "Achilleas Pipinellis",
      "web_url" : "https://gitlab.com/u/axil",
      "id" : 3585,
      "state" : "active"
   },
   "issues_enabled" : true,
   "visibility_level" : 0,
   "star_count" : 0,
   "last_activity_at" : "2015-08-19T22:10:41.503Z"
}

watch that its namespace_id is 3467. So that’s the number you are looking for. For a list of namespaces you are part of, run:

curl --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v3/namespaces"

As for the description, I guess you used spaces right? Make sure to replace them with %20 or + like:

curl --header "PRIVATE-TOKEN: token" -X POST "https://gitlab.com/api/v3/projects?name=foobartest4&description=This%20is%20a%20description"

See https://en.wikipedia.org/wiki/Percent-encoding for more info.

Tip: If you have perl installed you can pipe the output of the curl commands to | json_pp and the information will be more human readable :smile:

2 Likes