Skip to content

Instantly share code, notes, and snippets.

@jg75
Created July 10, 2018 17:50
Show Gist options
  • Save jg75/172de8e499a6bcef07ec0a4b634a701e to your computer and use it in GitHub Desktop.
Save jg75/172de8e499a6bcef07ec0a4b634a701e to your computer and use it in GitHub Desktop.
#! /bin/bash
api='https://api.amberengine.com'
auth='<your email>:<your password>'
split-array() {
awk '{
gsub(/^\[/, "")
gsub(/\]$/, "")
gsub(/ /, "")
gsub(/\"/, "")
split($0, array, ",")
for (i in array) {
printf("\n%s", array[i])
}
}'
}
get-brands() {
curl -u $auth $api/brands 2> /dev/null | split-array
}
get-products() {
local brand=$1
local limit=100
local offset=0
while true
do
local url="$api/brands/$brand/products?limit=$limit&offset=$offset"
local products=$(curl -u $auth $url 2> /dev/null)
if [ "$products" == "[]" ]
then
break
else
((offset+=limit))
echo $products
fi
done
}
brands=($(get-brands))
for brand in ${brands[@]}
do
get-products $brand
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment