gitlab-apigitlab-ee

REST API to create multiple groups in gitlab at once


I have installed GitLab EE (11.4.7-ee). I'm trying to create mulitplr groups using REST API.

https://testserver/gitlab/api/v4/groups

Post Data:

[
    { "name": "test1", "path": "test1" },
    { "name": "test2", "path": "test2" },
    { "name": "test3", "path": "test3" }
    ]

Error Message :

{ "error": "name is missing, path is missing" }

How to create many groups in one GitLab Group create Rest API


Solution

  • I have written the python script to craete multiple group in gitlab

    import requests
    import json
    import urllib3
    
    with open('./jfmjson.json', 'r') as f:
        jfm_dict = json.load(f)
    
    for jfm in jfm_dict:
        print(jfm['path'])
        gitlab_url = "https://testserver/gitlab/api/v4/groups"
        headers = {'Content-type': 'application/json', 'PRIVATE-TOKEN': 'pxpR3sehJ-xYzz61XxAs'}
        data = {'name': jfm['path'], 'path': jfm['path'], 'description': jfm['name']}
        urllib3.disable_warnings()
        r = requests.post(gitlab_url, data=json.dumps(data), headers=headers, verify=False)