1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
6 * OpenAPI SupplierPartCodes Endpoint
7 * GET /api/v1/openapi/supplier-part-codes?spid=1&pid=123
8 * Retrieve supplier part codes for products
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 pid = searchParams.get('pid');
27 if (pid) params.pid = parseInt(pid);
29 const enabled = searchParams.get('enabled');
30 if (enabled) params.enabled = enabled;
32 const partCodes = await fieldpineServerApi.apiCall("/SupplierPartCodes", {
34 cookie: authData.apiKey,
38 return NextResponse.json({
45 console.error('SupplierPartCodes API error:', error);
46 return NextResponse.json(
47 { error: 'Failed to fetch supplier part codes' },