TypeScript SDK
The official TypeScript SDK provides typed methods for all API endpoints.
Installation
Section titled “Installation”npm install @weplaytestgames/sdkQuick Start
Section titled “Quick Start”import { WPGClient } from '@weplaytestgames/sdk';
const client = new WPGClient({ apiKey: process.env.WPG_API_KEY!,});
// List your gamesconst games = await client.games.list();
// Create a playtestconst playtest = await client.playtests.create('game_abc123', { visibility: 'private', quantity: 3, instructions: 'Focus on the tutorial',});
// Check credit balanceconst balance = await client.billing.getBalance();console.log(`Balance: $${balance.balanceCents / 100}`);Authentication
Section titled “Authentication”Pass your API key when creating the client:
const client = new WPGClient({ apiKey: 'wpg_sk_...', // Optional: custom base URL for testing baseUrl: 'https://app.weplaytestgames.com/api/v1',});Error Handling
Section titled “Error Handling”The SDK throws typed errors:
import { WPGClient, WPGError } from '@weplaytestgames/sdk';
try { await client.playtests.create('game_abc', { visibility: 'private', quantity: 1 });} catch (error) { if (error instanceof WPGError) { console.log(error.code); // 'PAYMENT_REQUIRED' console.log(error.message); // 'Insufficient credit' console.log(error.status); // 402 }}Pagination
Section titled “Pagination”List methods return async iterables:
// Iterate all gamesfor await (const game of client.games.list()) { console.log(game.name);}
// Or get a single pageconst page = await client.games.list({ limit: 10 });console.log(page.data);console.log(page.meta.hasMore);Available Methods
Section titled “Available Methods”| Namespace | Methods |
|---|---|
client.auth | me(), updateProfile(), categories(), devices(), platforms() |
client.games | list(), create(), get(), update() |
client.playtests | create(), list(), get(), update(), slots() |
client.slots | get(), accept(), reject(), downloadUrl(), transcript() |
client.submissions | list() |
client.playtester | profile(), updateProfile(), stats(), openPlaytests(), myPlaytests() |
client.playtester.slots | get(), reserve(), release(), submit(), dispute() |
client.billing | getBalance(), payments(), purchaseCredit() |
client.payouts | list(), quote(), request(), cancel() |
client.chat | contacts(), conversation(), sendMessage(), unreadCount() |
client.notifications | list(), markAllRead() |
client.webhooks | list(), create(), update(), delete(), deliveries(), test(), enable(), rotateSecret() |