TypeScript SDK

We maintain a SDK for JavaScript runtimes (Node.js and browsers).

QuickstartCopied!

pnpm add @polar-sh/sdk
import { Polar } from '@polar-sh/sdk'

const polar = new Polar({
  accessToken: process.env['POLAR_ACCESS_TOKEN'] ?? '',
})

async function run() {
  const result = await polar.users.benefits.list({})

  for await (const page of result) {
    // Handle the page
    console.log(page)
  }
}

run()

Read more

Sandbox EnvironmentCopied!

You can configure the SDK so it hits the sandbox environment instead of the production one. You just need to add the server property to the configuration object:

const polar = new Polar({
  server: 'sandbox',
  accessToken: process.env['POLAR_ACCESS_TOKEN'] ?? '',
})