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 BUCK endpoint for sale list
15 let endpoint = "/buck?3=retailmax.elink.sale.list";
17 // Add all filters from query parameters
18 const filters = searchParams.getAll("filter");
19 const limit = searchParams.get("limit");
20 const fields = searchParams.get("fields");
22 if (fields) endpoint += `&10=${fields}`;
23 if (limit) endpoint += `&8=${limit}`;
25 // Add filters (field predicates)
26 for (const filter of filters) {
27 endpoint += `&9=${filter}`;
30 const result = await fieldpineServerApi.buckApiCall(endpoint, authData.apiKey!);
32 return NextResponse.json({
37 } catch (error: any) {
38 console.error("Error fetching sales list:", error);
39 return NextResponse.json(
40 { success: false, error: error.message || "Failed to fetch sales list" },
41 { status: error.status || 500 }