1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
6 * OpenAPI PurchaseOrder Parse Endpoint
7 * GET /api/v1/openapi/purchase-order/parse?text=...
8 * POST /api/v1/openapi/purchase-order/parse (with file upload)
9 * Parse text or files to extract purchase order information
11export async function GET(request: NextRequest) {
13 const authData = await getStoredAuth();
14 if (!authData || !authData.authenticated) {
15 return NextResponse.json(
16 { error: 'Authentication required' },
21 const { searchParams } = new URL(request.url);
22 const text = searchParams.get('text');
25 return NextResponse.json(
26 { error: 'text parameter required' },
31 const result = await fieldpineServerApi.apiCall("/PurchaseOrder/Parse", {
33 cookie: authData.apiKey,
37 return NextResponse.json({
44 console.error('PurchaseOrder Parse API error:', error);
45 return NextResponse.json(
46 { error: 'Failed to parse purchase order' },
52export async function POST(request: NextRequest) {
54 const authData = await getStoredAuth();
55 if (!authData || !authData.authenticated) {
56 return NextResponse.json(
57 { error: 'Authentication required' },
62 const formData = await request.formData();
64 // Note: File upload handling would need multipart/form-data support
65 const result = await fieldpineServerApi.apiCall("/PurchaseOrder/Parse", {
68 cookie: authData.apiKey,
72 return NextResponse.json({
79 console.error('PurchaseOrder Parse POST error:', error);
80 return NextResponse.json(
81 { error: 'Failed to parse purchase order file' },