Back to APIs

Manage digital storefronts, products, and sales.

Using the Lemon Squeezy API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your Lemon Squeezy background job resumable and appear in our dashboard.

Use io.runTask() and the official SDK or fetch.

Example code using Lemon Squeezy

Below is a working code example of how you can use Lemon Squeezy with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import z from "zod";
2
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
3
4
// The import path here has been updated because of conflict between commonjs and ESmodule
5
// when using in proper ESmodule setup you won't have to do this
6
import LemonSqueezy from "@lemonsqueezy/lemonsqueezy.js/dist/index.cjs";
7
8
// Get API key from https://docs.lemonsqueezy.com/api#authentication
9
const ls = new LemonSqueezy(process.env.LEMONSQUEEZY_API_KEY!);
10
11
// Using the official SDK; https://github.com/lmsqueezy/lemonsqueezy.js
12
client.defineJob({
13
id: "get-lemon-squeezy-store-details",
14
name: "Get Lemon Squeezy store details",
15
version: "1.0.0",
16
trigger: eventTrigger({
17
name: "get-lemon-squeezy-store-details",
18
schema: z.object({
19
id: z.string(),
20
include: z
21
.array(
22
z.enum([
23
"products",
24
"discounts",
25
"license-keys",
26
"subscriptions",
27
"webhooks",
28
])
29
)
30
.optional(),
31
}),
32
}),
33
run: async (payload, io) => {
34
await io.runTask(
35
"Get Lemon Squeezy store details",
36
async () => {
37
const store = await ls.getStore({
38
id: payload.id,
39
include: payload.include,
40
});
41
// The return value has to be JSON serializable as it's stored in the database.
42
return JSON.parse(JSON.stringify(store));
43
},
44
45
// Add metadata to improve how the task displays in the logs
46
{ name: "Get Lemon Squeezy store details", icon: "lemonSqueezy" }
47
);
48
},
49
});