Back to roadmaps lemonsqueezy Course

Lemon Squeezy API and Webhooks Cheat Sheet

This quick reference guide summarizes the most common patterns and configurations in Lemon Squeezy using the official JavaScript SDK.


1. SDK Client Initialization

import { lemonSqueezySetup } from "@lemonsqueezy/lemonsqueezy.js";

// Initialize the API client
lemonSqueezySetup({
  apiKey: "ey_your-api-key-string",
});

2. Generating Checkout Links

import { createCheckout } from "@lemonsqueezy/lemonsqueezy.js";

const checkout = await createCheckout("your-store-id", "variant-id-to-purchase", {
  checkoutData: {
    email: "customer@gmail.com",
    custom: {
      userId: "user-123",
    },
  },
});

3. Webhook Signature Headers Verification

import crypto from "crypto";

const signature = headers.get("x-signature");
const calculated = crypto
  .createHmac("sha256", "your-webhook-secret-key")
  .update(rawBody)
  .digest("hex");

const isValid = crypto.timingSafeEqual(
  Buffer.from(signature, "hex"),
  Buffer.from(calculated, "hex")
);

4. Licensing Endpoints Reference

Action HTTP Endpoint Url Required Payload
Activate /v1/licenses/activate license_key, instance_name
Validate /v1/licenses/validate license_key, instance_id
Deactivate /v1/licenses/deactivate license_key, instance_id
Published on Last updated: