MCPcopy Create free account
hub / github.com/9d8dev/directory / POST

Function POST

app/api/subscribe/route.ts:5–39  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

3const LOOPS_API_KEY = process.env.LOOPS_API_KEY;
4
5export async function POST(request: Request) {
6 try {
7 const { email, source, userGroup } = await request.json();
8
9 if (!email) {
10 return NextResponse.json({ error: "Email is required" }, { status: 400 });
11 }
12
13 const response = await fetch(
14 "https://app.loops.so/api/v1/contacts/create",
15 {
16 method: "POST",
17 headers: {
18 Authorization: `Bearer ${LOOPS_API_KEY}`,
19 "Content-Type": "application/json",
20 },
21 body: JSON.stringify({ email, source, userGroup }),
22 },
23 );
24
25 if (!response.ok) {
26 throw new Error("Failed to create contact in Loops");
27 }
28
29 const data = await response.json();
30
31 return NextResponse.json({ success: true, id: data.id }, { status: 201 });
32 } catch (error) {
33 console.error("Error in subscribe API:", error);
34 return NextResponse.json(
35 { error: "Internal Server Error" },
36 { status: 500 },
37 );
38 }
39}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected