1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
6 * OpenAPI Stocktakes Endpoint
7 * GET /api/v1/openapi/stocktakes?location=1&state=current
8 * List defined stocktakes
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 location = searchParams.get('location');
24 if (location) params.location = parseInt(location);
26 const state = searchParams.get('state');
27 if (state) params.state = state;
29 const stocktakes = await fieldpineServerApi.apiCall("/Stocktakes", {
31 cookie: authData.apiKey,
35 return NextResponse.json({
42 console.error('Stocktakes API error:', error);
43 return NextResponse.json(
44 { error: 'Failed to fetch stocktakes' },