1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
6 * OpenAPI SupplierMarketingMessages Endpoint
7 * GET /api/v1/openapi/supplier-marketing-messages
8 * List current marketing messages from suppliers
10export async function GET(request: NextRequest) {
12 const authData = await getStoredAuth();
13 if (!authData || !authData.authenticated) {
14 return NextResponse.json(
15 { error: 'Authentication required' },
20 const { searchParams } = new URL(request.url);
21 const params: Record<string, string | number> = {};
23 const spid = searchParams.get('spid');
24 if (spid) params.spid = parseInt(spid);
26 const from = searchParams.get('from');
27 if (from) params.from = from;
29 const to = searchParams.get('to');
30 if (to) params.to = to;
32 const pid = searchParams.get('pid');
33 if (pid) params.pid = parseInt(pid);
35 const messages = await fieldpineServerApi.apiCall("/SupplierMarketingMessages", {
37 cookie: authData.apiKey,
41 return NextResponse.json({
48 console.error('SupplierMarketingMessages API error:', error);
49 return NextResponse.json(
50 { error: 'Failed to fetch supplier marketing messages' },