Our SDK makes it simple to use our API. It’s a wrapper around our GraphQL API with pre-built functions for all of our endpoints. The endpoints are outlined in the SDK reference section of our docs.

Install

pnpm add @whop-apps/sdk

Setup your client

Create a new file that instantiates the client and exports it. We recommend putting this file at lib/whop-api.ts.

This file reads your ENV keys, which can be found on your app developer page on the Whop dashboard.

import { WhopServerSdk, makeUserTokenVerifier } from "@whop/api";

export const whopApi = WhopServerSdk({
  // Add your app api key here - this is required.
  // You can get this from the Whop dashboard after creating an app in the "API Keys" section.
  appApiKey: process.env.WHOP_API_KEY ?? "fallback",

  // This will make api requests on behalf of this user.
  // This is optional, however most api requests need to be made on behalf of a user.
  // You can create an agent user for your app, and use their userId here.
  // You can also apply a different userId later with the `withUser` function.
  onBehalfOfUserId: process.env.WHOP_AGENT_USER_ID,

  // This is the companyId that will be used for the api requests.
  // When making api requests that query or mutate data about a company, you need to specify the companyId.
  // This is optional, however if not specified certain requests will fail.
  // This can also be applied later with the `withCompany` function.
  companyId: undefined,
});

export const verifyUserToken = makeUserTokenVerifier({
  appId: process.env.WHOP_APP_ID ?? "fallback",
  dontThrow: true,
});

Example usage

The rest of the examples in this section will use this client and import it from lib/whop-api.ts.

Here is an example

import { whopApi } from "./lib/whop-api";

const user = await whopApi.getCurrentUser();