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.
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))
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With