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 Products Search Endpoint with Natural Language
7 * GET /api/v1/openapi/products-search?querytext=sold this month
8 * Supports free-form natural language queries
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 | number> = {};
22
23 const querytext = searchParams.get('querytext');
24 if (querytext) params.querytext = querytext;
25
26 const want = searchParams.get('want');
27 if (want) params.want = want;
28
29 const like = searchParams.get('like');
30 if (like) params.like = like;
31
32 const limit = searchParams.get('limit');
33 if (limit) params.limit = parseInt(limit);
34
35 const option = searchParams.get('option');
36 if (option) params.option = option;
37
38 const ref = searchParams.get('ref');
39 if (ref) params.ref = ref;
40
41 const inputmethod = searchParams.get('inputmethod');
42 if (inputmethod) params.inputmethod = inputmethod;
43
44 const products = await fieldpineServerApi.apiCall("/ProductsSearch", {
45 params,
46 cookie: authData.apiKey,
47 useOpenApi: true
48 });
49
50 return NextResponse.json({
51 success: true,
52 data: products,
53 source: 'openapi'
54 });
55
56 } catch (error) {
57 console.error('ProductsSearch API error:', error);
58 return NextResponse.json(
59 { error: 'Failed to search products' },
60 { status: 500 }
61 );
62 }
63}