EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
route.ts
Go to the documentation of this file.
1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
4
5/**
6 * Email Send Log Endpoint
7 * GET /api/v1/messaging/email/sendlog - Get email send logs
8 * Query params:
9 * 101 - From date (inclusive)
10 * 102 - To date (exclusive)
11 */
12export async function GET(request: NextRequest) {
13 try {
14 const authData = await getStoredAuth();
15 if (!authData || !authData.authenticated) {
16 return NextResponse.json(
17 { error: 'Authentication required' },
18 { status: 401 }
19 );
20 }
21
22 // Extract query parameters
23 const searchParams = request.nextUrl.searchParams;
24 const queryParams: Record<string, string> = {};
25
26 // Date filters
27 const fromDate = searchParams.get('101');
28 const toDate = searchParams.get('102');
29
30 if (fromDate) queryParams['101'] = fromDate;
31 if (toDate) queryParams['102'] = toDate;
32
33 console.log('[Email Log API] Fetching with params:', queryParams);
34
35 // Call Fieldpine API
36 const response = await fieldpineServerApi.apiCall('/buck', {
37 params: {
38 '3': 'messaging.email.sendlog',
39 ...queryParams
40 },
41 cookie: authData.apiKey,
42 useOpenApi: false
43 });
44
45 return NextResponse.json({
46 success: true,
47 data: response
48 });
49
50 } catch (error) {
51 console.error('[Email Log API] Error:', error);
52 return NextResponse.json(
53 { error: 'Failed to fetch email logs' },
54 { status: 500 }
55 );
56 }
57}