I'm trying to create a subgroup via the API and need an example please

My powershell looks like this (hey don’t be afraid … its readable)
It works for Groups but not for SubGroups.
I’m wondering how the Uri needs to be formed and if the “group” is in the path parameter or in the uri prefix to the “?” question mark like /$group/groups or /groups/$groups?name=…

$header = @{“PRIVATE-TOKEN”=“$global:GitApiKey”}
$Path = “$Group/$Subgroup”
$Path_Encoded = [System.Web.HttpUtility]::UrlEncode($Path)

$groups = Invoke-RestMethod -Head $header -Uri “$Urlprefix/groups?name=$Subgroup&path=$Path_Encoded” -Method Post

Write-Host $groups

I found the issue. Our GitLab server is 10.0 and needs to be 10.3 or greater.

OK still stuck creating subgroups via the api.
Is this supported?

I can’t find the API for creating subgroups in the documentation

Ok problem solved. There is no subgroup API. Subgroups are groups with Parent_id specified. So to create a Subgroup you use the Group API and specify the Parent_id which is the integer id of the group. The group api group/ will return the first id with that matching name.

Example HTML Post:
https ://gitlab.com/api/v4/groups?name=newkksub&path=newkksub&visibility=internal&lfs_enabled=true&description=“newkkgroup newkksub created by api call”&parent_id=7

2 Likes

@Knight21024 Thanks a lot for your caring to document that, I just ran into the exat same issue, solved the exact same way …