Skip to content

About

Typescript SDK to interact with the Whop API

Resources

Contributing

Stars

16 stars

Watchers

0 watching

Forks

Repository files navigation

Whop TypeScript SDK

Call the Whop API from TypeScript or JavaScript.

Install

Use Node.js 18 or later.

npm install @whop/sdk@2.8.1

Read products

Set WHOP_API_KEY to your sandbox API key. Save this example as read-products.mjs. It reads public products from the test environment.

import { WhopClient, WhopEnvironment } from "@whop/sdk";

const client = new WhopClient({
    environment: WhopEnvironment.Sandbox,
    token: process.env.WHOP_API_KEY,
});
const products = await client.products.list({ first: 1 });
console.log(products.data.length);

Run the example:

node read-products.mjs

Pass your API key as token to create products. Keep business API keys on your server.

Watch a read

Some reads are live: the API sends their answer again each time it changes. Their client has watch and waitFor beside the read, taking the same request. watch yields the read's answer now and after each change, and reconnects on its own when the connection drops.

const stop = new AbortController();
setTimeout(() => stop.abort(), 60_000);

for await (const series of client.stats.timeSeries.watch(
    { metric: "gmv_usd", account_id: "biz_...", from: "2026-11-01", to: "2026-11-30" },
    { abortSignal: stop.signal },
)) {
    console.log(series.data.points.at(-1));
}

waitFor resolves with the first answer until accepts, and rejects after timeoutMs (30 seconds unless you pass another):

const series = await client.stats.timeSeries.waitFor(
    { metric: "gmv_usd", account_id: "biz_...", from: "2026-11-01", to: "2026-11-30" },
    { until: (series) => series.data.points.length === 30, timeoutMs: 120_000 },
);

Both also take the read's request options, maxBackoffMs (the longest wait between reconnects) and onDisconnect (called on each drop).

API reference · API guide

About

Typescript SDK to interact with the Whop API

Resources

Contributing

Stars

16 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages