Quickstart

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
camelCase vs. snake_caseOur API (and docs) is designed with snake_case. However, our TS SDK currently converts this to camelCase to follow JS/TS convention. You should automatically see the camelCase parameters suggested in modern IDEs due to typing, but it’s worth keeping in mind switching between code & docs.We aim to introduce the ability to toggle this in the future, i.e using snake_case even in TypeScript to more easily map it to our documentation and design of the API itself.

Framework Adapters

Implement Checkout & Webhook handlers in 5 lines of code.

Sandbox Environment

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'] ?? '',
})