EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
route.ts
Go to the documentation of this file.
1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
4
5/**
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
10 */
11export async function GET(request: NextRequest) {
12 try {
13 const authData = await getStoredAuth();
14 if (!authData || !authData.authenticated) {
15 return NextResponse.json(
16 { error: 'Authentication required' },
17 { status: 401 }
18 );
19 }
20
21 const { searchParams } = new URL(request.url);
22 const text = searchParams.get('text');
23
24 if (!text) {
25 return NextResponse.json(
26 { error: 'text parameter required' },
27 { status: 400 }
28 );
29 }
30
31 const result = await fieldpineServerApi.apiCall("/PurchaseOrder/Parse", {
32 params: { text },
33 cookie: authData.apiKey,
34 useOpenApi: true
35 });
36
37 return NextResponse.json({
38 success: true,
39 data: result,
40 source: 'openapi'
41 });
42
43 } catch (error) {
44 console.error('PurchaseOrder Parse API error:', error);
45 return NextResponse.json(
46 { error: 'Failed to parse purchase order' },
47 { status: 500 }
48 );
49 }
50}
51
52export async function POST(request: NextRequest) {
53 try {
54 const authData = await getStoredAuth();
55 if (!authData || !authData.authenticated) {
56 return NextResponse.json(
57 { error: 'Authentication required' },
58 { status: 401 }
59 );
60 }
61
62 const formData = await request.formData();
63
64 // Note: File upload handling would need multipart/form-data support
65 const result = await fieldpineServerApi.apiCall("/PurchaseOrder/Parse", {
66 method: 'POST',
67 body: formData,
68 cookie: authData.apiKey,
69 useOpenApi: true
70 });
71
72 return NextResponse.json({
73 success: true,
74 data: result,
75 source: 'openapi'
76 });
77
78 } catch (error) {
79 console.error('PurchaseOrder Parse POST error:', error);
80 return NextResponse.json(
81 { error: 'Failed to parse purchase order file' },
82 { status: 500 }
83 );
84 }
85}