Skip to content

Commit 746949a

Browse files
Merge pull request #74 from thoughtspot/SCAL-295232-liveboard-schedule-webhook
SCAL-295232 Add Liveboard schedule webhook example
2 parents fcd2e5e + fe1cfc4 commit 746949a

16 files changed

Lines changed: 3077 additions & 0 deletions

File tree

‎rest-api/Readme.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
4. [Trusted auth server typescript](./trusted-auth-server-typescript/)
1111
5. [Trusted auth server python](./trusted-auth-server-python/)
1212
6. [Org inactive users cleanup](./ts-org-inactive-users-cleanup/)
13+
7. [Liveboard schedule webhook](./liveboard-schedule-webhook/)
1314

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Receiver (npm start)
2+
PORT=3000
3+
# Bearer token ThoughtSpot sends to the receiver (the webhook's authentication).
4+
# If empty, the endpoint accepts requests from anyone: local testing only.
5+
RECEIVER_TOKEN=
6+
# Google Drive folder ID in a shared drive; leave empty to write files to ./out
7+
DRIVE_FOLDER_ID=
8+
# Service-account key file for Drive
9+
GOOGLE_APPLICATION_CREDENTIALS=
10+
# Storage mode reads S3 with the AWS default credential chain (needs s3:GetObject)
11+
12+
# ThoughtSpot setup (npm run setup)
13+
TS_HOST=https://your-instance.thoughtspot.cloud
14+
TS_TOKEN=
15+
WEBHOOK_URL=https://receiver.example.com/webhooks/thoughtspot
16+
# Optional S3 storage destination
17+
S3_BUCKET=
18+
S3_REGION=
19+
S3_ROLE_ARN=
20+
# AWS-hosted clusters only
21+
S3_EXTERNAL_ID=
22+
S3_PATH_PREFIX=
23+
# route-schedules: set for one Org, leave empty for the whole cluster
24+
ORG_IDENTIFIER=
25+
# validate: the id printed by create-webhook
26+
WEBHOOK_ID=
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
out
3+
.env
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"installDependencies": true,
3+
"startCommand": "npm run dev"
4+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<!-- search-meta
2+
tags: [webhooks, Liveboard-schedule, REST-API, AWS-S3, Google-Drive, TypeScript, NodeJS, Express, rest-api-sdk]
3+
apis: [createWebhookConfiguration, getWebhookStorageConfig, configureCommunicationChannelPreferences, validateCommunicationChannel, LIVEBOARD_SCHEDULE, REST-API-v2]
4+
questions:
5+
- How do I receive a scheduled ThoughtSpot Liveboard through a webhook?
6+
- How do I handle ThoughtSpot webhook deliveries with PDF/CSV/XLSX attachments in Node.js?
7+
- How do I deliver Liveboard schedule files to an AWS S3 bucket with ThoughtSpot webhooks?
8+
- How do I upload ThoughtSpot scheduled Liveboard exports to Google Drive?
9+
- How do I route Liveboard schedules to the webhook communication channel?
10+
-->
11+
12+
# Liveboard schedule webhook (Typescript)
13+
14+
A webhook receiver, built with TypeScript and Express, for ThoughtSpot **Liveboard schedule** events. When a scheduled Liveboard runs, ThoughtSpot exports it (PDF, CSV or XLSX) and delivers it to this receiver, which uploads the files to a Google Drive folder.
15+
16+
ThoughtSpot delivers in one of two ways, depending on whether the webhook has a storage destination:
17+
18+
| | Direct (no storage destination) | Storage (S3 destination) |
19+
|---|---|---|
20+
| Files | Inside the request | Written to your S3 bucket by ThoughtSpot |
21+
| Request | `multipart/form-data`: a `payload` part with the event JSON, one `file` part per attachment | The event JSON plus a `files[]` list with each file's `objectKey` |
22+
| Receiver needs | Nothing extra | Its own `s3:GetObject` access to the bucket |
23+
24+
```mermaid
25+
sequenceDiagram
26+
participant TS as ThoughtSpot
27+
participant S3 as Your S3 bucket
28+
participant Rx as This receiver
29+
participant GD as Google Drive
30+
alt Direct
31+
TS->>Rx: POST multipart (payload + files)
32+
else Storage
33+
TS->>S3: PutObject (assumes your IAM role)
34+
TS->>Rx: POST event JSON + files[]
35+
end
36+
Rx-->>TS: 200 within 5 seconds
37+
opt Storage
38+
Rx->>S3: GetObject(objectKey)
39+
end
40+
Rx->>GD: Upload files
41+
```
42+
43+
## Key Usage
44+
45+
Simplified from [`src/main.ts`](src/main.ts):
46+
47+
```typescript
48+
app.post('/webhooks/thoughtspot', checkBearerToken, express.json(), async (req, res) => {
49+
// Direct: event from the "payload" part, attachments from the "file" parts.
50+
// Storage: event is the JSON body; files[] says where each file is in S3.
51+
const { event, files } = await parseDelivery(req);
52+
53+
// ThoughtSpot retries deliveries that fail or take longer than 5 seconds,
54+
// so skip repeats (data.msgUniqueId) and acknowledge before uploading.
55+
const key = event.data.msgUniqueId ?? event.eventId;
56+
if (!markSeen(key)) return reply(res, 200, 'Duplicate delivery; already received');
57+
reply(res, 200, 'Webhook received successfully');
58+
59+
// Fetch from S3 and upload to Drive, retrying each file with backoff.
60+
queue = queue.then(() => processDelivery(event, files));
61+
});
62+
```
63+
64+
File structure:
65+
66+
```
67+
liveboard-schedule-webhook
68+
├── src
69+
│ ├── main.ts # The receiver: parse, acknowledge, fetch from S3, upload to Drive
70+
│ ├── setup.ts # ThoughtSpot-side setup with @thoughtspot/rest-api-sdk
71+
│ └── demo.ts # npm run dev / npm test: sends sample deliveries to the receiver
72+
├── fixtures # Sample deliveries from the payload documentation
73+
├── .env.example
74+
├── .stackblitzrc
75+
└── package.json
76+
```
77+
78+
## Demo
79+
80+
Open in [StackBlitz](https://stackblitz.com/github/thoughtspot/developer-examples/tree/main/rest-api/liveboard-schedule-webhook)
81+
82+
`npm run dev` needs no ThoughtSpot instance or cloud credentials. It sends the receiver three deliveries: a direct one, a storage one (one file stored, one failed), and a retry of the first. The files are written to `out/` instead of Drive.
83+
84+
## Documentation
85+
86+
- [Webhooks overview](https://developers.thoughtspot.com/docs/webhooks-overview)
87+
- [Webhook for Liveboard schedule events](https://developers.thoughtspot.com/docs/webhooks-lb-schedule)
88+
- [Webhook communication channel](https://developers.thoughtspot.com/docs/webhooks-comm-channel)
89+
- [Webhook payload](https://developers.thoughtspot.com/docs/webhooks-lb-payload)
90+
- [AWS S3 storage for webhooks](https://developers.thoughtspot.com/docs/webhooks-s3-integration)
91+
- [REST API playground: create webhook](https://try-everywhere.thoughtspot.cloud/v2/#/everywhere/api/rest/playgroundV2_0?apiResourceId=http%2Fapi-endpoints%2Fwebhooks%2Fcreate-webhook-configuration)
92+
93+
## Run locally
94+
95+
- Clone the repository
96+
97+
```bash
98+
git clone https://github.com/thoughtspot/developer-examples.git
99+
cd developer-examples/rest-api/liveboard-schedule-webhook
100+
```
101+
102+
- Install dependencies (Node 22 or later) and try the demo
103+
104+
```bash
105+
npm install
106+
npm run dev
107+
```
108+
109+
- Copy `.env.example` to `.env` and set the variables:
110+
111+
| Variable | Description |
112+
| --- | --- |
113+
| `RECEIVER_TOKEN` | Bearer token ThoughtSpot sends to the receiver; the receiver rejects requests without it. If unset, the endpoint accepts requests from anyone, so only leave it empty for local testing |
114+
| `DRIVE_FOLDER_ID` | Drive folder to upload to. It must be in a shared drive, with the service account as a member. Leave empty to write to `out/` |
115+
| `GOOGLE_APPLICATION_CREDENTIALS` | Service-account key file for Drive |
116+
| `TS_HOST`, `TS_TOKEN` | Your ThoughtSpot instance, and a bearer token for the setup calls |
117+
| `WEBHOOK_URL` | Where ThoughtSpot can reach the receiver (HTTPS). To inspect raw deliveries first, see [See a raw delivery first](#see-a-raw-delivery-first-optional) |
118+
| `S3_BUCKET`, `S3_REGION`, `S3_ROLE_ARN`, `S3_EXTERNAL_ID`, `S3_PATH_PREFIX` | Optional S3 storage destination |
119+
120+
- Start the receiver and make it reachable from your ThoughtSpot instance, for example with [ngrok](https://ngrok.com/) or by deploying it. For storage mode, it also needs AWS credentials with `s3:GetObject` on the bucket.
121+
122+
```bash
123+
npm start
124+
```
125+
126+
- Set up ThoughtSpot, in this order:
127+
128+
| Step | Command | API |
129+
| --- | --- | --- |
130+
| 1. S3 only: get ThoughtSpot's AWS account or GCP service account and a trust-policy template | `npm run setup -- storage-config` | `GET /api/rest/2.0/webhooks/storage-config` |
131+
| 2. S3 only: create the bucket and an IAM role with that trust policy, allowed `s3:PutObject` and `s3:PutObjectAcl` | AWS console | [S3 storage docs](https://developers.thoughtspot.com/docs/webhooks-s3-integration) |
132+
| 3. Create the webhook | `npm run setup -- create-webhook` | `POST /api/rest/2.0/webhooks/create` |
133+
| 4. Send Liveboard schedules to it. Until then, they keep going to email | `npm run setup -- route-schedules` | `POST /api/rest/2.0/system/preferences/communication-channels/configure` |
134+
| 5. Send a test delivery (set `WEBHOOK_ID` to the id from step 3) | `npm run setup -- validate` | `POST /api/rest/2.0/system/communication-channels/validate` |
135+
| 6. Schedule a Liveboard | Liveboard **Schedule** menu | |
136+
137+
For step 2, how the trust policy works depends on where your cluster is hosted:
138+
- **AWS-hosted clusters:** it uses an external ID (case-sensitive), passed as `S3_EXTERNAL_ID`.
139+
- **GCP-hosted clusters:** register `accounts.google.com` as an identity provider, and condition the trust on `accounts.google.com:sub` and `:aud`.
140+
141+
### See a raw delivery first (optional)
142+
143+
To see exactly what ThoughtSpot sends before you run the receiver, use a temporary [webhook.site](https://webhook.site) URL as `WEBHOOK_URL`:
144+
145+
```bash
146+
curl -s -X POST https://webhook.site/token | jq -r '"https://webhook.site/" + .uuid'
147+
```
148+
149+
Run the setup steps above with that URL, then open it in a browser to see each delivery. Switch `WEBHOOK_URL` to the receiver once you're done.
150+
151+
A free webhook.site URL has limits:
152+
153+
- **It's public.** Anyone with the URL can read the deliveries, including the bearer token. Use test data and a throwaway `RECEIVER_TOKEN`.
154+
- **It expires after 7 days or 100 requests.** Then create a new one and update the existing webhook's URL in the Webhooks UI or with `POST /api/rest/2.0/webhooks/{webhook_identifier}/update`. You can't create a second webhook: only one is allowed per Org.
155+
- **It rejects requests over 10 MB.** ThoughtSpot records larger deliveries as failed and retries them.
156+
- **It shows only the last attachment of a direct-mode delivery**, because ThoughtSpot names every attachment part `file`. The event JSON and storage-mode deliveries arrive in full.
157+
158+
### Before you start
159+
160+
- Webhooks are Beta. ThoughtSpot Support enables them, together with the COMS mail agent and template-variable service they need. Without those, schedules fail with `WEBHOOK_PREREQUISITE_NOT_MET`.
161+
- Only Liveboard schedule events use the webhook channel today, and only one Liveboard schedule webhook is allowed per Org.
162+
- Minimum versions:
163+
- 10.14.0.cl: webhook APIs;
164+
- 26.3.0.cl: S3 storage;
165+
- 26.4.0.cl: `validate`;
166+
- 26.7.0.cl: `storage-config`.
167+
- Privileges: `ADMINISTRATION` or `DEVELOPER` (with RBAC, `CAN_MANAGE_WEBHOOKS` also works). Cluster-wide channel preferences need `ADMINISTRATION`.
168+
169+
### Not covered
170+
171+
These can be added on top of `src/main.ts`:
172+
- GCS storage destinations;
173+
- signature verification: the docs don't specify what is signed or how;
174+
- a durable queue and shared dedupe store: the in-memory ones here are lost on restart and don't work across receiver instances.
175+
176+
## Technology labels
177+
178+
- Typescript
179+
- NodeJS
180+
- Express
181+
- REST API SDK
182+
- AWS S3
183+
- Google Drive
184+
- Webhook
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"eventId": "n.18bd8bd5-dee3-4d5c-918e-aec3ba1a090f",
3+
"timestamp": "2025-08-29T09:25:32Z",
4+
"eventType": "LIVEBOARD_SCHEDULE",
5+
"schemaVersion": "1.0",
6+
"source": {
7+
"applicationName": "ThoughtSpot",
8+
"applicationUrl": "https://my.thoughtspot.cloud",
9+
"instanceId": "3d85f2fe-8489-11f0-bdf8-5ba90",
10+
"orgId": "2100019165"
11+
},
12+
"actor": { "actorType": "SYSTEM" },
13+
"metadataObject": {
14+
"objectType": "LIVEBOARD",
15+
"id": "c30a0d49-5747-475d-8985-e975b1c2cf6d",
16+
"name": "Sample Liveboard (View: sample view name)",
17+
"url": "https://my.thoughtspot.cloud/#/pinboard/c30a0d49-5747-475d-8985-e975b1c2cf6d?view=a8118b21-4581-4315-8833-39b2aa5be542"
18+
},
19+
"data": {
20+
"scheduleDetails": {
21+
"scheduleId": "cffddca8-d4fc-4575-b8ec-a50e696ccdfc",
22+
"name": "Sample Liveboard",
23+
"creationTime": "2025-08-29T07:52:23Z",
24+
"description": "Daily sales performance report",
25+
"authorId": "59481331-ee53-42be-a548-bd87be6ddd4a",
26+
"viewInfo": { "viewId": "a8118b21-4581-4315-8833-39b2aa5be542", "viewName": "sample view name" },
27+
"userIds": ["59481331-ee53-42be-a548-bd87be6ddd4a"],
28+
"groupIds": [],
29+
"runId": "29001ffd-6a84-45cd-a957-621fce89afc6",
30+
"exportRequest": {
31+
"object_type": "LIVEBOARD",
32+
"pdf_params": { "orientation": "LANDSCAPE", "page_size": "A4" },
33+
"request_type": "SCHEDULE"
34+
},
35+
"fileFormat": "pdf",
36+
"status": "SCHEDULED",
37+
"emailIds": []
38+
},
39+
"recipients": [
40+
{ "type": "USER", "id": "user-123", "name": "John Doe", "email": "john@company.com", "locale": "en_US" }
41+
],
42+
"viewInfo": { "viewId": "a8118b21-4581-4315-8833-39b2aa5be542", "viewName": "sample view name" },
43+
"aiHighlights": "Sales increased by 15% compared to last quarter",
44+
"msgUniqueId": "2f31df6a-2623-4953-a9bb-5af9b2922474",
45+
"channelID": "6dfa4d82-fdc8-4d5b-8294-a5de0dd5ede1",
46+
"channelType": "webhook",
47+
"communicationType": "LiveboardSchedules"
48+
}
49+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"eventId": "n.7c1e2a90-4b3d-4f5e-9a8b-1c2d3e4f5a6b",
3+
"timestamp": "2026-02-26T09:25:32Z",
4+
"eventType": "LIVEBOARD_SCHEDULE",
5+
"schemaVersion": "1.0",
6+
"source": {
7+
"applicationName": "ThoughtSpot",
8+
"applicationUrl": "https://your-cluster.thoughtspot.cloud",
9+
"instanceId": "your-instance-id",
10+
"orgId": "0"
11+
},
12+
"actor": { "actorType": "SYSTEM" },
13+
"metadataObject": {
14+
"objectType": "LIVEBOARD",
15+
"id": "c30a0d49-5747-475d-8985-e975b1c2cf6d",
16+
"name": "Sales Dashboard",
17+
"url": "https://your-cluster.thoughtspot.cloud/#/pinboard/c30a0d49-5747-475d-8985-e975b1c2cf6d"
18+
},
19+
"data": {
20+
"scheduleDetails": {
21+
"scheduleId": "cffddca8-d4fc-4575-b8ec-a50e696ccdfc",
22+
"name": "Daily Sales Report",
23+
"creationTime": "2026-02-26T07:52:23Z",
24+
"description": "Daily report",
25+
"authorId": "59481331-ee53-42be-a548-bd87be6ddd4a",
26+
"userIds": ["59481331-ee53-42be-a548-bd87be6ddd4a"],
27+
"groupIds": [],
28+
"runId": "29001ffd-6a84-45cd-a957-621fce89afc6",
29+
"exportRequest": { "object_type": "LIVEBOARD", "request_type": "SCHEDULE" },
30+
"fileFormat": "pdf",
31+
"status": "SCHEDULED",
32+
"emailIds": []
33+
},
34+
"recipients": [
35+
{ "type": "USER", "id": "59481331-ee53-42be-a548-bd87be6ddd4a", "name": "John Doe", "email": "john@company.com", "locale": "en_US" }
36+
],
37+
"aiHighlights": "",
38+
"msgUniqueId": "8a4f0c6e-1d2b-4e3f-a5b6-c7d8e9f0a1b2",
39+
"channelID": "6dfa4d82-fdc8-4d5b-8294-a5de0dd5ede1",
40+
"channelType": "webhook",
41+
"communicationType": "LiveboardSchedules"
42+
}
43+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
region,revenue
2+
North,120000
3+
South,98000
218 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)