1
Get recently added customers Trigger
One script reply has been approved by the moderators Verified

Trigger script to get the newly created customers.

Created by adam186 770 days ago Viewed 14802 times
In Windmill, a trigger script is designed to pull data from an external source and return all the new items since the last run. It operates without resorting to external webhooks and is typically used with schedules and states to compare the current execution to the previous one.
0
Submitted by adam186 Deno
Verified 770 days ago
1
import {
2
  getState,
3
  setState,
4
} from "https://deno.land/x/windmill@v1.85.0/mod.ts";
5
import Stripe from "https://esm.sh/stripe@11.4.0?target=deno";
6

7
type Stripe = {
8
  token: string;
9
};
10
export async function main(auth: Stripe) {
11
  const stripe = new Stripe(auth.token, {
12
    httpClient: Stripe.createFetchHttpClient(),
13
  });
14
  const lastCheck = (await getState()) || 0;
15
  await setState(Date.now());
16
  const customers = await stripe.customers.list({
17
    created: { gt: lastCheck },
18
  });
19
  return customers.data;
20
}
21