Skip to content

Instantly share code, notes, and snippets.

@louisscruz
Created October 23, 2017 20:06
Show Gist options
  • Save louisscruz/b13b844758bbfe483d210f81950565c9 to your computer and use it in GitHub Desktop.
Save louisscruz/b13b844758bbfe483d210f81950565c9 to your computer and use it in GitHub Desktop.
create_account
#!/bin/sh
COUNT_FILE=~/Code/zendesk/scripts/create_account/create_account_count.txt
create_count_file() {
echo '1' > $COUNT_FILE
}
ensure_count_file() {
if [ ! -f $COUNT_FILE ]; then
echo 'Creating a count file'
create_count_file
fi
}
get_count() {
cat $COUNT_FILE
}
handle_increment_count() {
local CURRENT_COUNT=$(get_count)
echo $(($CURRENT_COUNT + 1)) > $COUNT_FILE
}
make_request() {
curl -v -d 'owner[name]=Louis Cruz' \
-d 'owner[email]=lcruz@zendesk.com' \
-d 'owner[password]=password' \
-d 'owner[is_verified]=1' \
-d 'address[phone]=1234567890' \
-d 'account[name]=Louis Cruz' \
-d 'account[subdomain]='$1 \
-d 'account[help_desk_size]=Large group' \
-d 'account[language]=en' \
-d 'terms=terms_and_things' \
-H 'Authorization: Bearer 0ae8899b8624384922ed49cfd89ab5020eb8f77bf008d6e12f6a08e620f0fcea' \
https://zendeskaccounts.zd-dev.com/api/v2/accounts.json
}
create_account() {
ensure_count_file
local SUB_NAME=lcruz$(get_count)
make_request $SUB_NAME
handle_increment_count
echo
echo 'Account created!'
echo 'Here are your account details:'
echo 'lcruz@zendesk.com'
echo 'password'
echo $SUB_NAME
}
create_account
@louisscruz
Copy link
Author

This assumes that you keep scripts in ~/Code/zendesk/scripts. Place this in ~/Code/zendesk/scripts/. Then, alias the script in your ~/.bash_profile. For instance, I added alias caccount='~/Code/zendesk/scripts/create_account/create_account'. You might need to run chmod +x ~/Code/zendesk/scripts/create_account/create_account to have permission to run it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment