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 * SMS Send Log Endpoint
7 * GET /api/v1/messaging/sms/sendlog - Get SMS send logs
8 * Query params:
9 * 8 - Row limit (default 500)
10 * 160 - Direction filter (1=sent, 2=received, 3=both)
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 // Row limit
27 const rowLimit = searchParams.get('8');
28 if (rowLimit) queryParams['8'] = rowLimit;
29
30 // Direction filter
31 const directionFilter = searchParams.get('160');
32 if (directionFilter) queryParams['160'] = directionFilter;
33
34 console.log('[SMS Log API] Fetching with params:', queryParams);
35
36 // Call Fieldpine API
37 const response = await fieldpineServerApi.apiCall('/buck', {
38 params: {
39 '3': 'messaging.sms.sendlog',
40 ...queryParams
41 },
42 cookie: authData.apiKey,
43 useOpenApi: false
44 });
45
46 return NextResponse.json({
47 success: true,
48 data: response
49 });
50
51 } catch (error) {
52 console.error('[SMS Log API] Error:', error);
53 return NextResponse.json(
54 { error: 'Failed to fetch SMS logs' },
55 { status: 500 }
56 );
57 }
58}