2
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: application/json" \
  --data '{"path": "<subgroup_path>", "name": "<subgroup_name>", "parent_id": <parent_group_id> } \
  "https://gitlab.example.com/api/v4/groups/"

I was following the documentation from gitlab. I just wanted to to know how to represent the part after --data as a python request. Will it be a part of params, json or any other parameter in requests module?

Any help is appreciated. Thank you.

Abercrombie
  • 1,012
  • 2
  • 13
  • 22

2 Answers2

6

Here's the equivalent using requests:

import requests
import json

headers = {
    "PRIVATE-TOKEN": "<your_access_token>",
    "Content-Type": "application/json",
}
data = {
    "path": "<subgroup_path>",
    "name": "<subgroup_name>",
    "parent_id": "<parent_group_id>",
}

requests.post("https://gitlab.example.com/api/v4/groups/",
    headers=headers, data=json.dumps(data))
tzaman
  • 46,925
  • 11
  • 90
  • 115
4

It can be done by python's requests package.

import requests
import json

url = "https://gitlab.example.com/api/v4/groups/"
headers = {'PRIVATE-TOKEN': '<your_access_token>', 'Content-Type':'application/json'}
data = {"path": "<subgroup_path>", "name": "<subgroup_name>", "parent_id": <parent_group_id>}

requests.post(url, data=json.dumps(data), headers=headers)

reference : Python Request Post with param data

Prashant Godhani
  • 337
  • 1
  • 4
  • 15