Back to jobs

Updates customer information in Plain

Trigger: eventTrigger

Updates or creates customer information based on an identifier.

Integrations:

/src/plainUpdateCustomer

Databases

1
import { Job, TriggerClient, eventTrigger } from "@trigger.dev/sdk";
2
import {
3
ComponentDividerSpacingSize,
4
ComponentTextColor,
5
ComponentTextSize,
6
Plain,
7
} from "@trigger.dev/plain";
8
9
const client = new TriggerClient({ id: "jobs-showcase" });
10
11
export const plain = new Plain({
12
id: "plain",
13
apiKey: process.env.PLAIN_API_KEY!,
14
});
15
16
// This Job will use update a customer's information in Plain based on an identifier.
17
client.defineJob({
18
id: "plain-update-customer",
19
name: "Plain: update customer",
20
version: "1.0.0",
21
integrations: {
22
plain,
23
},
24
trigger: eventTrigger({
25
name: "plain.update.customer",
26
}),
27
run: async (payload, io, ctx) => {
28
const { customer } = await io.plain.upsertCustomer("upsert-customer", {
29
identifier: {
30
emailAddress: "[email protected]",
31
},
32
// If customer isn't found they should be created
33
onCreate: {
34
email: {
35
36
isVerified: true,
37
},
38
fullName: "Rick Astley",
39
externalId: "u_123",
40
},
41
// If customer is found their details will be updated
42
onUpdate: {
43
fullName: {
44
value: "Rick Astley",
45
},
46
// This is the id of the customer in your own backend.
47
externalId: {
48
value: "u_123",
49
},
50
},
51
});
52
},
53
});
54
55
// These lines can be removed if you don't want to use express
56
import { createExpressServer } from "@trigger.dev/express";
57
createExpressServer(client);