1import { NextRequest, NextResponse } from "next/server";
2import { fieldpineServerApi } from "@/lib/server/fieldpineApi";
3import { getStoredAuth } from "@/lib/server/auth";
5export async function GET(request: NextRequest) {
7 const authData = await getStoredAuth();
9 return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
12 const { searchParams } = new URL(request.url);
14 // Build endpoint for price changes
15 let endpoint = "/buck?3=retailmax.elink.pricechange.list";
17 const limit = searchParams.get("limit");
18 const search = searchParams.get("search");
19 const pluList = searchParams.get("pluList");
20 const showType = searchParams.get("showType");
23 endpoint += `&9=f120,0,${showType}`;
27 endpoint += `&8=${limit}`;
31 endpoint += `&9=f101,like,${encodeURIComponent(search)}`;
35 endpoint += `&9=f100,in,${encodeURIComponent(pluList)}`;
38 const result = await fieldpineServerApi.buckApiCall(endpoint, authData.apiKey!);
40 return NextResponse.json({
42 data: result.DATS || [],
45 } catch (error: any) {
46 console.error("Error fetching price changes:", error);
47 return NextResponse.json(
48 { success: false, error: error.message || "Failed to fetch price changes" },
49 { status: error.status || 500 }