Skip to content

Latest commit

 

History

History
98 lines (70 loc) · 10.9 KB

README.md

File metadata and controls

98 lines (70 loc) · 10.9 KB

TypeScript Examples for the Looker API

The examples in this folder use yarn. If you don't have yarn installed already, you'll need to install it.

Using yarn

Use

yarn {command} [other command-line options]

to run a TypeScript SDK example file.

Setup and run the typescript examples

These examples assume that a looker.ini has been created in the root of the repository (two directories up from this directory).

  1. Change directory into this directory (examples/typescript).
  2. Run yarn to install the dependencies.
  3. Run the examples - yarn {command} [other command-line options]
    • yarn run-dual - runs multiple apis example.
    • yarn run-tiny-dual - runs the compact multiple apis example
    • yarn run-config - runs custom config reader example.
    • yarn run-sudo - runs sudo as user example.
    • yarn run-tile - runs download dashboard tile example.
    • yarn run-dashboard - runs download dashboard example.
    • yarn run-bulk-disable-schedules - runs bulk disable schedules example.
    • yarn run-bulk-reassign-schedules - runs bulk reassign schedules example.
    • yarn run-validate-branch - runs validate branch example.
    • yarn run-generate-api-credentials - runs bulk generate api credentials example.
    • yarn run-test-connections - runs test connections example.
    • yarn run-pdt-mapping - runs pdt mapping example.
    • yarn run-create-slack-alert - runs create slack alert example.
    • yarn bulk-delete-alerts - runs bulk delete alerts example.

Some other dependencies may be required for the projects to build and run correctly on your local clone.

yarn install @types/readable-stream @types/request @types/request-promise-native -D

TypeScript SDK packages

The Looker TypeScript SDK has different packages to prevent node dependencies being linked into browser usage of the SDK (the node dependencies are not available in the browser and can cause compilation errors). There are three packages for the Typescript SDK available on npm:

  1. @looker/sdk-rtl - contains a run time library needed to invoke the Looker API methods. Referencing the @looker/sdk as a dependency should automatically pull this package in.
  2. @looker/sdk - contains the Looker API methods.
  3. @looker/sdk-node - contains the dependencies needed to run the Looker SDK in a node environment. Do NOT include this package if you are using the Looker SDK in a browser. You MUST include this package if you are using node or ts-node.

Example list

A very brief descriptions of the examples, and the link to the main example/project file are provided here. For more information on an example, look at the source file.

General examples

  Example Topic   Discussion
multiple APIs A simple example that shows how to use multiple versions of the API in the same file. The goal is to make iterative migration from an older API to a newer API in existing SDK code easier.
custom configReader Shows how to implement a custom method of reading your configuration settings, including API credentials
SDK utilities This file has some SDK utility methods tasks like:
  • finding a dashboard by name
  • listing dashboards and ids
  • finding a tile on a dashboard
  • listing queryable tiles for a dashboard
  • a general-purpose waitForRender routine with progress ticks

User management

  Example Topic   Discussion
sudo as user Uses several User management SDK methods and shows how to sudo as a different user than the default API credentials user. Once the auth session is set to that user, subsequent SDK requests will be "as user <x>" when submitted to the API.
bulk generate api credentials Allows an admin to generate api credentials in bulk given a Looker role ID as input (Ex: generate api credentials for all users with the "Developer" role).

Schedules & Alerts

  Example Topic   Discussion
bulk disable schedules This script allows an admin user to disable all user schedules OR just the schedules of a specific user.
bulk reassign schedules This script allows allows an admin user to either reassign all user schedules OR a single user's schedules to a specified user.
bulk delete alerts This script allows an admin user to bulk delete alerts for a specific user on the instance.
create slack alert This script allows a user to create an alert on a tile of a given dashboard element that sends an alert message to slack when triggered. Users will need at least the create_alerts role to be able to run this call. Configuration variables are outlined in the script.

Git / LookML Project Validation

  Example Topic   Discussion
validate branch Allows you to validate a given branch of a specific project in development mode, returning any validation errors that are surfaced.

Connection / PDT

  Example Topic   Discussion
test connections Allows an admin user to run connection tests in bulk outputting a results object with the results of the test for each db connection in Looker.
pdt mapping This file allows you to map out your pdt dependencies for a given model in an output svg file.

Downloading

  Example Topic   Discussion
download a dashboard tile by name Find the requested dashboard by name, then the requested tile by name. If either name matches, the list of all available items is display. Supported output formats are PNG, JPG, CSV, JSON, and anything else supported by the run_query endpoint. This sample shows progress during a render task, and also how to use the SDK's streaming support.
download a dashboard by name Find the requested dashboard by name, then render it in the requested format. Default render format is PDF. PDF or PNG are the recommended output formats, but JPG is also supported.