Skip to main content
This guide shows you how to programmatically create an Omni workbook with multiple SQL-based tabs using a bash script. Automating workbook creation is helpful for generating standardized analysis templates or migrating queries from other systems into Omni.

Requirements

To follow along with this guide, you’ll need:
  • An Omni API token
  • To install jq, which is a lightweight JSON processor. The script in this guide uses it to build and parse JSON payloads. Refer to the jq documentation for installation instructions.
  • The following information from your Omni instance:
    • The subdomain of your Omni URL, for example blobsrus
    • The ID of the model you want to query

Implementation

The following script uses curl to send a POST request to the /api/v1/documents endpoint. It defines four distinct SQL queries and organizes them into a single workbook with specific visualization types: line charts, bar charts, and tables. This part of the guide walks through different parts of the script and how they work. Refer to the Run the script section for a full copy-pasteable version of the script.
1

Script configuration

The first part of the script contains your Omni information, which you’ll need to define before running the script:
  • OMNI_INSTANCE - The subdomain of your Omni instance
  • OMNI_API_TOKEN - Your Omni API key
  • MODEL_ID - The ID of the model you want to query
  • DOCUMENT_NAME - The name of the document you’ll create
  • BASE_TABLE - The name of an existing view in your Omni model. This cannot be an arbitrary string.
    Each query can point to a different base table. The examples in this guide all reference the same order_items table for simplicity, but one query could point to orders while another points to products.Omni recommends pointing to a view that is contextually related to the query being defined. While the field primarily serves as a reference point, using an unrelated view may produce unexpected behavior.
Script configuration
2

SQL queries

The SQL queries section defines the actual SQL queries that will be ported into the workbook.
SQL queries
3

API request

Use the Model ID found in the URL of your model IDE to ensure the workbook targets the correct data schema.
The API request portion of the script uses the information in the Configuration and SQL queries sections to build the curl request.The queryPresentations array defines the individual query tabs (tiles) within the workbook. Each query tab object contains a few parameters that are worth highlighting:
  • isSql: true - This parameter tells Omni to treat the userEditedSQL string as the primary source of truth for the query
  • visConfig - This parameter sets the default visualization style for the query tab, such as line, bar, or table
The following snippet highlights these parameters in the script:
API request

Run the script

The following code example is a full copy-pasteable version of the script. To use it:
  1. Save this version to a convenient location.
  2. Replace the configuration variables with your Omni information.
  3. Use the command line to run the script!
Full copy-pasteable script version

Next steps

Once you run the script, the API will return a JSON object containing a workbook identifier. You can navigate to https://[instance].omniapp.co/dashboards/[identifier] to view your new multi-tab analysis.