Last active
October 12, 2018 21:12
-
-
Save lasseebert/c0a35b0ee90c90476a6374d69210e121 to your computer and use it in GitHub Desktop.
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/bash | |
# | |
# Fetches users from the Wise Home API. Requires valid email and password to run. | |
# | |
# Requirements: | |
# - jq (https://stedolan.github.io/jq/download/) | |
# | |
# Usage: | |
# fetch_users_from_legolas_by_property.sh <email> <password> <property_id> | |
set -e | |
email=$1 | |
password=$2 | |
property_id=$3 | |
api_url="https://api.wisehome.dk" | |
function print_usage { | |
echo "Usage:" | |
echo "" | |
echo " ./fetch_users_from_legolas_by_property.sh <email> <password> <property_id>" | |
} | |
if [ ! -n "$email" ]; then | |
print_usage | |
exit 1 | |
fi | |
if [ ! -n "$password" ]; then | |
print_usage | |
exit 1 | |
fi | |
if [ ! -n "$property_id" ]; then | |
print_usage | |
exit 1 | |
fi | |
api_key=$( | |
curl "$api_url/account-users?filter[role]=angel" -u "$email:$password" 2>/dev/null \ | |
| jq --raw-output '.data[0].attributes."api-key"' | |
) | |
curl "$api_url/properties/$property_id" -u ":$api_key" 2>/dev/null \ | |
| jq --raw-output ' | |
.included | |
| . - map(select(.type != "households")) | |
| map(.relationships.tenant.data.id) | |
| map(select(. != null)) | |
| .[] | |
' \ | |
| while read tenant_id; do | |
curl "$api_url/accounts/$tenant_id/users" -u ":$api_key" 2>/dev/null \ | |
| jq --raw-output ' | |
.data | |
| map( | |
. | |
| { | |
id: .id, | |
name: .name, | |
email: .attributes.email, | |
"activated-at": .attributes."activated-at", | |
"activation-token": .attributes."activation-token" | |
} | |
)' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment