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 Barcodes Endpoint
7 * GET /api/v1/openapi/barcodes?scan=9384848284
8 * Decodes barcodes and returns product/item information
9 */
10export async function GET(request: NextRequest) {
11 try {
12 const authData = await getStoredAuth();
13 if (!authData || !authData.authenticated) {
14 return NextResponse.json(
15 { error: 'Authentication required' },
16 { status: 401 }
17 );
18 }
19
20 const { searchParams } = new URL(request.url);
21 const params: Record<string, string> = {};
22
23 const scan = searchParams.get('scan');
24 if (!scan) {
25 return NextResponse.json(
26 { error: 'scan parameter required' },
27 { status: 400 }
28 );
29 }
30 params.scan = scan;
31
32 const geo = searchParams.get('geo');
33 if (geo) params.geo = geo;
34
35 const barcode = await fieldpineServerApi.apiCall("/Barcodes", {
36 params,
37 cookie: authData.apiKey,
38 useOpenApi: true
39 });
40
41 return NextResponse.json({
42 success: true,
43 data: barcode,
44 source: 'openapi'
45 });
46
47 } catch (error) {
48 console.error('Barcodes API error:', error);
49 return NextResponse.json(
50 { error: 'Failed to decode barcode' },
51 { status: 500 }
52 );
53 }
54}