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 490 days ago Viewed 6694 times
0
Submitted by adam186 Deno
Verified 490 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