interworks/thoughtspotrest

This package allows simple REST API communication with your ThoughtSpot cluster.

v0.0.4 2024-10-30 21:40 UTC

This package is auto-updated.

Last update: 2025-03-29 01:09:19 UTC


README

GitHub Workflow Status (Pest) GitHub Workflow Status (PHPStan) Latest Version License

This is a simple API for calling REST API's against your ThoughtSpot cluster. It handles authentication for you so install, add the environment variables, and start making REST API calls!

Getting Started

Installation

Requires PHP >= 8.2.

composer require interworks/thoughtspotrest

Next, add the following required environment variables to your .env file:

THOUGHTSPOT_REST_URL="https://YOUR-ORG.thoughtspot.cloud"
THOUGHTSPOT_REST_USERNAME="YOUR_USER"

Then, depending on your desired authentication, add these:

"Basic" authentication:

THOUGHTSPOT_REST_AUTH_TYPE="basic"
THOUGHTSPOT_REST_PASSWORD="YOUR_USER_PASSWORD"

"Trusted" authentication:

THOUGHTSPOT_REST_AUTH_TYPE="trusted"
THOUGHTSPOT_REST_SECRET_KEY="123abc-..."

"Cookie" authentication:

THOUGHTSPOT_REST_AUTH_TYPE="cookie"
THOUGHTSPOT_REST_PASSWORD="YOUR_USER_PASSWORD"

For more information on ThoughtSpot REST API authentication options, view their doc here.

Documentation

Every REST API call in ThoughtSpot's documentation has a function to call it with the same name in camel case. For instance, the "Search Metadata" API call can be called with:

$ts->searchMetadata($args);

ThoughtSpot's REST API documentation can be found here.

Usage Guide

Basic Usage

Instantiate a ThoughtSpotREST object and start making calls!

use InterWorks\ThoughtSpotREST\ThoughtSpotREST;

// Instantiate
$ts = new ThoughtSpotREST();

// Get first 10 Liveboards and create a collection.
$liveboards = $ts->searchMetadata(['metadata' => ['type' => 'LIVEBOARD'], 'record_size' => 10]);
$liveboards = collect($liveboards);

// Get a user by name and update it
$users  = $ts->searchUsers(['user_identifier' => 'jlyons', 'record_size' => 1]);
$user   = collect($users)->first();
$userID = $user['id'];
$ts->updateUser($userID, ['email' => 'justin.lyons@interworks.com']);

Unsupported Endpoints

If there's an endpoint missed, you can use the call function to specify the URL, arguments, and method. The function returns a Illuminate\Http\Client\Response object.

$response = $ts->call(
    url   : 'metadata/search',
    args  : ['metadata' => ['type' => 'LIVEBOARD'], 'record_size' => 10],
    method: 'POST'
);
$response->json();

Function Return Type Options

By default, either an array or boolean will be returned depending on the endpoint. If you'd like more control over how the response is processed, you can set returnResponseObject to true in the constructor to always receive the Illuminate\Http\Client\Response object.

$ts         = new ThoughtSpotREST(returnResponseObject: true);
$response   = $ts->searchMetadata(['metadata' => ['type' => 'LIVEBOARD'], 'record_size' => 10]);
$success    = $response->successful();
$body       = $response->body();
$liveboards = $response->json();

License

This package is released under the MIT License. See LICENSE for details.