(request: Request)
| 3 | const LOOPS_API_KEY = process.env.LOOPS_API_KEY; |
| 4 | |
| 5 | export 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected