Help creating a bash script for a REST API
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I need the following:

I have to run the following command:

curl '' \
-F 'url=' \
-F 'name=file_submission1.pdf' \
-F 'parent_folder_path=my_files/section1' \
-H "Authorization: Bearer MYGENERATEDTOKEN"

Which returns:


I then need to grab the ID, in this case "40" and run it through the next CURL command.

curl '' \
-F 'submission[submission_type]=online_upload' \
-F 'submission[file_ids][]=40' \
-H "Authorization: Bearer MYGENERATEDTOKEN"

I then need to run this for users 01-50, in effect so each user uploads a file, and then submits it via the API. I'd like this in the form of a bash script that I can modify on a per use basis, and executable from terminal on a Mac


you will run it with php or directly with bash?
Chlegou 1 year ago
awarded to 5osxcwbf

Crowdsource coding tasks.

2 Solutions



for i in {`seq -w 1 $i_max`}

json=$(`curl '$i' -F 'url=' -F 'name=file_submission1.pdf' -F 'parent_folder_path=my_files/section1' -H "Authorization: Bearer MYGENERATEDTOKEN`)

id=$(`$json | grep -Eo '"id":.*?[^\\]",' `)
curl '$i' -F 'submission[submission_type]=online_upload' -F 'submission[file_ids][]=$id' -H "Authorization: Bearer MYGENERATEDTOKEN"

try this and let me know :)
Subhash Dasyam 1 year ago
it seems like he also wants to be able to run it on a per-user basis, also using grep to parse stuff like html, json etc is a bad habit that sooner or later always comes back to haunt you.
5osxcwbf 1 year ago
I understand, but Simon said this need to be run on MAC OsX terminal where jq,python may not be available so i had to choose RE
Subhash Dasyam 1 year ago
Python comes preinstalled on Mac osx.
5osxcwbf 1 year ago
weird not int he case of mine. i had to install
Subhash Dasyam 1 year ago
Winning solution

So here is my solution, if you are unable to modify it yourself, just accept my answer so i get the bounty, and send the urls, access credential detail etc to my anti-spam email address;; i will send you the completely working version as soon as i receive your email. Oh and don't forget to run in bash "chmod +x" since the script executes itself recursively.


#if no argument is found, then we must recursively call ourselves; ./ user01, ./ user02 etc

if [ -z  "$USER" ]; then
    for i in `seq -w 01 50`; 
        echo "Recursively execute $0 user$i"
        #comment out below line to prevent everything from really executing
        $0 user$i

        #remove bellow comment to stop sleeping in between requests
        sleep 1
    exit 1;    

echo "Getting json for:$USER" 

#hardcoded json, uncomment the real curl request below to overwrite 

#curl "$USER" \
#-F 'url=' \
#-F 'name=file_submission1.pdf' \
#-F 'parent_folder_path=my_files/section1' \
#-H "Authorization: Bearer MYGENERATEDTOKEN"  \
echo $JSON 

#Filter id from json using python (which comes pre-installled on osx)
ID=$(echo $JSON  | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["id"]')

echo "id: $ID"

#curl "$USER" \
#-F 'submission[submission_type]=online_upload' \
#-F "submission[file_ids][]=$ID" \
#-H "Authorization: Bearer MYGENERATEDTOKEN"  \

Comments won't parse properly - I'll email you what I get
Simon 1 year ago
Just for clarity - the ID changes with ever user, so I've uncommented out the first CURL command - however it looks like the python command is not working: File "", line 1, in KeyError: 'id' id:
Simon 1 year ago
I just emailed you :]
5osxcwbf 1 year ago
Hello 5os, I need a brilliant developer to solve several ffmpeg issues. I can increase the budget. I have just posted a bounty of $10 as I need to know if anyone is capable of solving ffmpeg tasks. You have solved complex bounties before. Do you think you can take this one and more related ffmpeg bounties? Please see . Thank you!
georgefountain 1 year ago
View Timeline