3
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.

2 Answers 2

7

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))
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.