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

Hi, no I haven’t tried anything and later, I forgot about it.

Hello marabaa, after much despair and read and read (for not knowing python) I managed to make the loop, this has to be done before starting the POST request, when you indicate the JSON =, you should not enter all the JSON as it will give errors, these data have to collect them as a variable, for example after defining the starting data Username and Pasword, or create the file and import it, once collected the JSON data, in the POST request you must intruducir JSON = VARIABLE.
You have to be very careful with the JSON structure because in my tests it has caused me many errors.
I hope it helps you.
imagen
imagen
[EDIT]
With curl, I have had many problems, personally I would recommend using python.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.