Skip to main content

Examples

Installation

Terminal
npm install @polar-sh/sdk

Quickstart

index.js
import { Polar } from '@polar-sh/sdk'

const polar = new Polar({
  accessToken: process.env.POLAR_ACCESS_TOKEN,
  server: process.env.POLAR_MODE || 'sandbox' // sandbox or production
})

async function run() {
  const result = await polar.users.benefits.list({})
  for await (const page of result) {
    // Handle the page
    console.log(page)
  }
}

run()
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 few lines of code.