// Create a record
const res = await fetch(`${BASE_URL}/collection/customers`, {
method: "POST",
headers: {
"x-api-key": process.env.TOKEN,
"content-type": "application/json",
},
body: JSON.stringify({ name: "John", surname: "Doe" }),
});
// Send a webhook event
await fetch(`${BASE_URL}/webhook/push-event`, {
method: "POST",
headers: {
"x-api-key": process.env.TOKEN,
"content-type": "application/json",
},
body: JSON.stringify({
event: "customer.updated",
occurred_at: new Date().toISOString(),
data: { id: "cus_8h2", active: true },
}),
});
// Subscribe to an SSE channel
const events = new EventSource(
"https://sse.jetstack.dev/you-app/subscribe/event",
{ headers: { "x-api-key": process.env.TOKEN } }
);
events.onmessage = (e) => {
console.log(JSON.parse(e.data));
};