Last active
August 29, 2015 14:24
-
-
Save aserrallerios/ab84100828cf2afa536a to your computer and use it in GitHub Desktop.
Bulk download from API with cURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
echo "First parameter must be the CSV file containing the names and the ids separated by COMMAS" | |
echo "For example: | |
name,id | |
NAME_1,1234 | |
NAME_2,1235 | |
..." | |
if [[ -z $1 ]]; then | |
exit 1 | |
fi | |
echo "The header of the input file will be removed" | |
for line in $(tail -n +2 $1 | cut -d',' -f1-2 --output-delimiter=';'); do | |
name=$(echo $line | cut -f1 -d';'); | |
id=$(echo $line | cut -f2 -d';'); | |
echo "name: $name" | |
echo "id: $id" | |
echo '{ | |
"report" : false, | |
"desk" : "'$id'", | |
"format" : "CSV", | |
"separator" : "SEMICOLON", | |
"delimiter" : "DOUBLE_QUOTES", | |
"schema" : | |
{} | |
}' > ./temp.txt | |
curl -k -f -H "Content-type: text/json" -H "Authorization: Basic abcdefghijklmnopqrstuvwxyz1234567890" -X POST "https://host/path" -d "@./temp.txt" > ./$name.csv | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment