Skip to content

Instantly share code, notes, and snippets.

@lawrencejones
Last active March 26, 2020 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawrencejones/e871dcb1e88efd31e1f46fa7d79191d5 to your computer and use it in GitHub Desktop.
Save lawrencejones/e871dcb1e88efd31e1f46fa7d79191d5 to your computer and use it in GitHub Desktop.
Looker API helper
# Source this file ($ source <file-namne>) in your terminal to load all the
# functions.
# First run the looker-login using the client ID and client secret to generate
# an API token. Once you have your API token, run:
#
# $ export LOOKER_API_TOKEN=<your-token>
#
# This will enable use of looker-curl.
# looker-create-token <client-id> <client-secret>
function looker-create-token() {
CLIENT_ID=$1; : "${CLIENT_ID:="$LOOKER_API_CLIENT_ID"}"
CLIENT_SECRET=$1; : "${CLIENT_SECRET:="$LOOKER_API_CLIENT_SECRET"}"
curl \
--silent \
-H "Content-Type: application/json" \
-X POST \
-d "" \
"https://looker-api.gocardless.io/api/3.0/login?client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET"
}
# Automatically set the LOOKER_API_TOKEN
function looker-login() {
LOOKER_API_TOKEN="$(looker-create-token | jq -r .access_token)"
export LOOKER_API_TOKEN
}
# You can now run looker-curl like so:
#
# $ looker-curl looks | jq 'map(.title)'
# $ looker-curl spaces | jq 'map({id: .id, name: .name})'
#
# looker-curl <url> <extra-args>*
function looker-curl() {
curl --silent \
-H "Authorization: Bearer $LOOKER_API_TOKEN" \
-H "Content-Type: application/json" \
"https://looker-api.gocardless.io/api/3.0/$1" \
"${@:2}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment