1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
6 * SMS Send Log Endpoint
7 * GET /api/v1/messaging/sms/sendlog - Get SMS send logs
9 * 8 - Row limit (default 500)
10 * 160 - Direction filter (1=sent, 2=received, 3=both)
12export async function GET(request: NextRequest) {
14 const authData = await getStoredAuth();
15 if (!authData || !authData.authenticated) {
16 return NextResponse.json(
17 { error: 'Authentication required' },
22 // Extract query parameters
23 const searchParams = request.nextUrl.searchParams;
24 const queryParams: Record<string, string> = {};
27 const rowLimit = searchParams.get('8');
28 if (rowLimit) queryParams['8'] = rowLimit;
31 const directionFilter = searchParams.get('160');
32 if (directionFilter) queryParams['160'] = directionFilter;
34 console.log('[SMS Log API] Fetching with params:', queryParams);
37 const response = await fieldpineServerApi.apiCall('/buck', {
39 '3': 'messaging.sms.sendlog',
42 cookie: authData.apiKey,
46 return NextResponse.json({
52 console.error('[SMS Log API] Error:', error);
53 return NextResponse.json(
54 { error: 'Failed to fetch SMS logs' },