REST-API Create multiple folders

Hi,

could someone please give me some hint how to create multiple folders with rest api? Using shell script. Documentation doesn’t show this thing, is it possible to do it?

Code part, I tried, but it creates only the last item, so “gws” under “kosice”. All parent folders are existing, I’ve created them manually via GUI.

out=$(
  curl \
    --request POST \
    --write-out "\nxxx-status_code=%{http_code}\n" \
    --header "Authorization: Bearer $USERNAME $PASSWORD" \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '{
            "name": "datanodes",
            "parent": "/data/amsterdam",
            "title": "Datanodes",
            "name": "gws",
            "parent": "/data/amsterdam",
            "title": "Gateways",
            "name": "datanodes",
            "parent": "/data/kosice",
            "title": "Datanodes",
            "name": "gws",
            "parent": "/data/kosice",
            "title": "Gateways"

        }'

If you put your data structure inside Python, you will see why it only creates one folder.

Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> data = {
...             "name": "datanodes",
...             "parent": "/data/amsterdam",
...             "title": "Datanodes",
...             "name": "gws",
...             "parent": "/data/amsterdam",
...             "title": "Gateways",
...             "name": "datanodes",
...             "parent": "/data/kosice",
...             "title": "Datanodes",
...             "name": "gws",
...             "parent": "/data/kosice",
...             "title": "Gateways"
...
...         }
>>>
>>>
>>> data
{'name': 'gws', 'parent': '/data/kosice', 'title': 'Gateways'}
>>>

You need to make one call per folder.

Okay, then I need to invent some loop which will insert bash variables into json string.

1 Like

Hello Marabaa, How did you create the loop?
I have tried to save the data in a variable to use it in a for loop but it is impossible to find a way to do it.
Thank you very much in advance