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 * Loyalty Campaigns Endpoint
7 * Uses Fieldpine's elink/BUCK API for loyalty management
8 */
9export async function GET(request: NextRequest) {
10 try {
11 // Verify authentication
12 const authData = await getStoredAuth();
13 if (!authData || !authData.authenticated) {
14 return NextResponse.json(
15 { success: false, error: 'Authentication required' },
16 { status: 401 }
17 );
18 }
19
20 // Call BUCK API for loyalty campaigns
21 try {
22 const buckParams = {
23 "3": "retailmax.elink.loyalty.list"
24 };
25
26 const response = await fieldpineServerApi.buckApiCall(buckParams, authData.apiKey);
27
28 // Extract campaigns from BUCK response
29 if (response?.DATS && Array.isArray(response.DATS)) {
30 return NextResponse.json({
31 success: true,
32 data: response.DATS,
33 source: 'elink'
34 });
35 } else {
36 return NextResponse.json({
37 success: true,
38 data: [],
39 source: 'elink'
40 });
41 }
42
43 } catch (error) {
44 console.error('Loyalty campaigns error:', error);
45 return NextResponse.json(
46 { success: false, error: 'Failed to fetch loyalty campaigns', source: 'elink' },
47 { status: 503 }
48 );
49 }
50
51 } catch (error) {
52 console.error('Loyalty API error:', error);
53 return NextResponse.json(
54 { success: false, error: 'Failed to fetch loyalty campaigns' },
55 { status: 500 }
56 );
57 }
58}