Browse Source

fix: correct ShopRenter API query parameters #87

Fixed incorrect query parameter names in ShopRenter MCP integration:
- Changed 'customer_email' to 'email' (line 660)
- Changed 'created_from/created_to' to 'createdAtMin/createdAtMax'
- Changed 'updated_from/updated_to' to 'updatedAtMin/updatedAtMax'
- Removed 'customer_name' parameter (not supported by ShopRenter API)

Updated files:
- supabase/functions/_shared/shoprenter-client.ts
- supabase/functions/mcp-shoprenter/index.ts

This resolves the 400 error:
"The given parameter: customer_email is not available!"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Claude 5 months ago
parent
commit
df4a755518

+ 15 - 19
supabase/functions/_shared/shoprenter-client.ts

@@ -608,12 +608,11 @@ export async function fetchProducts(storeId: string, page: number = 0, limit: nu
 
 
 export interface ShopRenterOrderFilters {
 export interface ShopRenterOrderFilters {
   status?: string;           // Filter by order status
   status?: string;           // Filter by order status
-  customer_email?: string;   // Filter by customer email
-  customer_name?: string;    // Filter by customer name
-  created_from?: string;     // ISO 8601 datetime
-  created_to?: string;       // ISO 8601 datetime
-  updated_from?: string;     // ISO 8601 datetime
-  updated_to?: string;       // ISO 8601 datetime
+  email?: string;            // Filter by customer email (correct parameter name)
+  createdAtMin?: string;     // ISO 8601 datetime - orders created after this date
+  createdAtMax?: string;     // ISO 8601 datetime - orders created before this date
+  updatedAtMin?: string;     // ISO 8601 datetime - orders updated after this date
+  updatedAtMax?: string;     // ISO 8601 datetime - orders updated before this date
   innerId?: string;          // Filter by customer-visible order number (innerId)
   innerId?: string;          // Filter by customer-visible order number (innerId)
 }
 }
 
 
@@ -656,23 +655,20 @@ export async function fetchOrders(
     if (filters.status) {
     if (filters.status) {
       endpoint += `&status=${filters.status}`
       endpoint += `&status=${filters.status}`
     }
     }
-    if (filters.customer_email) {
-      endpoint += `&customer_email=${encodeURIComponent(filters.customer_email)}`
-    }
-    if (filters.customer_name) {
-      endpoint += `&customer_name=${encodeURIComponent(filters.customer_name)}`
+    if (filters.email) {
+      endpoint += `&email=${encodeURIComponent(filters.email)}`
     }
     }
-    if (filters.created_from) {
-      endpoint += `&created_from=${encodeURIComponent(filters.created_from)}`
+    if (filters.createdAtMin) {
+      endpoint += `&createdAtMin=${encodeURIComponent(filters.createdAtMin)}`
     }
     }
-    if (filters.created_to) {
-      endpoint += `&created_to=${encodeURIComponent(filters.created_to)}`
+    if (filters.createdAtMax) {
+      endpoint += `&createdAtMax=${encodeURIComponent(filters.createdAtMax)}`
     }
     }
-    if (filters.updated_from) {
-      endpoint += `&updated_from=${encodeURIComponent(filters.updated_from)}`
+    if (filters.updatedAtMin) {
+      endpoint += `&updatedAtMin=${encodeURIComponent(filters.updatedAtMin)}`
     }
     }
-    if (filters.updated_to) {
-      endpoint += `&updated_to=${encodeURIComponent(filters.updated_to)}`
+    if (filters.updatedAtMax) {
+      endpoint += `&updatedAtMax=${encodeURIComponent(filters.updatedAtMax)}`
     }
     }
     if (filters.innerId) {
     if (filters.innerId) {
       endpoint += `&innerId=${encodeURIComponent(filters.innerId)}`
       endpoint += `&innerId=${encodeURIComponent(filters.innerId)}`

+ 31 - 48
supabase/functions/mcp-shoprenter/index.ts

@@ -80,7 +80,7 @@ const TOOLS: McpTool[] = [
   },
   },
   {
   {
     name: 'shoprenter_list_orders',
     name: 'shoprenter_list_orders',
-    description: 'List orders from a ShopRenter store with filtering. At least one filter is REQUIRED (created_from, created_to, updated_from, updated_to, customer_email, or customer_name). Returns order details including customer info, items, status, and totals. Limited to 20 results maximum.',
+    description: 'List orders from a ShopRenter store with filtering. At least one filter is REQUIRED (createdAtMin, createdAtMax, updatedAtMin, updatedAtMax, or email). Returns order details including customer info, items, status, and totals. Limited to 20 results maximum.',
     inputSchema: {
     inputSchema: {
       type: 'object',
       type: 'object',
       properties: {
       properties: {
@@ -88,30 +88,26 @@ const TOOLS: McpTool[] = [
           type: 'string',
           type: 'string',
           description: 'The UUID of the ShopRenter store from the stores table'
           description: 'The UUID of the ShopRenter store from the stores table'
         },
         },
-        created_from: {
+        createdAtMin: {
           type: 'string',
           type: 'string',
-          description: 'Filter orders created after this ISO 8601 datetime (e.g., 2025-01-01T00:00:00Z)'
+          description: 'Filter orders created after this ISO 8601 datetime (e.g., 2025-01-01T10:30:00)'
         },
         },
-        created_to: {
+        createdAtMax: {
           type: 'string',
           type: 'string',
-          description: 'Filter orders created before this ISO 8601 datetime'
+          description: 'Filter orders created before this ISO 8601 datetime (e.g., 2025-01-01T10:30:00)'
         },
         },
-        updated_from: {
+        updatedAtMin: {
           type: 'string',
           type: 'string',
-          description: 'Filter orders updated after this ISO 8601 datetime'
+          description: 'Filter orders updated after this ISO 8601 datetime (e.g., 2025-01-01T10:30:00)'
         },
         },
-        updated_to: {
+        updatedAtMax: {
           type: 'string',
           type: 'string',
-          description: 'Filter orders updated before this ISO 8601 datetime'
+          description: 'Filter orders updated before this ISO 8601 datetime (e.g., 2025-01-01T10:30:00)'
         },
         },
-        customer_email: {
+        email: {
           type: 'string',
           type: 'string',
           description: 'Filter by customer email address'
           description: 'Filter by customer email address'
         },
         },
-        customer_name: {
-          type: 'string',
-          description: 'Filter by customer name (searches billing name)'
-        },
         status: {
         status: {
           type: 'string',
           type: 'string',
           description: 'Filter by order status: any, pending, processing, on-hold, completed, cancelled, refunded, failed'
           description: 'Filter by order status: any, pending, processing, on-hold, completed, cancelled, refunded, failed'
@@ -307,24 +303,23 @@ async function handleGetOrder(args: Record<string, any>): Promise<ToolCallResult
 async function handleListOrders(args: Record<string, any>): Promise<ToolCallResult> {
 async function handleListOrders(args: Record<string, any>): Promise<ToolCallResult> {
   const {
   const {
     shop_id,
     shop_id,
-    created_from,
-    created_to,
-    updated_from,
-    updated_to,
-    customer_email,
-    customer_name,
+    createdAtMin,
+    createdAtMax,
+    updatedAtMin,
+    updatedAtMax,
+    email,
     status,
     status,
     limit = 5
     limit = 5
   } = args;
   } = args;
 
 
   // Validate at least one filter is provided
   // Validate at least one filter is provided
-  const hasFilter = created_from || created_to || updated_from || updated_to || customer_email || customer_name;
+  const hasFilter = createdAtMin || createdAtMax || updatedAtMin || updatedAtMax || email;
   if (!hasFilter) {
   if (!hasFilter) {
     return {
     return {
       content: [{
       content: [{
         type: 'text',
         type: 'text',
         text: JSON.stringify({
         text: JSON.stringify({
-          error: 'At least one filter is required: created_from, created_to, updated_from, updated_to, customer_email, or customer_name'
+          error: 'At least one filter is required: createdAtMin, createdAtMax, updatedAtMin, updatedAtMax, or email'
         })
         })
       }],
       }],
       isError: true
       isError: true
@@ -359,29 +354,18 @@ async function handleListOrders(args: Record<string, any>): Promise<ToolCallResu
   }
   }
 
 
   try {
   try {
-    // Build filters
+    // Build filters using correct parameter names
     const filters: ShopRenterOrderFilters = {};
     const filters: ShopRenterOrderFilters = {};
     if (status) filters.status = status;
     if (status) filters.status = status;
-    if (customer_email) filters.customer_email = customer_email;
-    if (created_from) filters.created_from = created_from;
-    if (created_to) filters.created_to = created_to;
-    if (updated_from) filters.updated_from = updated_from;
-    if (updated_to) filters.updated_to = updated_to;
+    if (email) filters.email = email;
+    if (createdAtMin) filters.createdAtMin = createdAtMin;
+    if (createdAtMax) filters.createdAtMax = createdAtMax;
+    if (updatedAtMin) filters.updatedAtMin = updatedAtMin;
+    if (updatedAtMax) filters.updatedAtMax = updatedAtMax;
 
 
     // Fetch orders from ShopRenter API
     // Fetch orders from ShopRenter API
-    let orders: any[];
-
-    if (customer_name) {
-      // If filtering by customer name, we need to fetch and filter locally
-      // because ShopRenter doesn't support name filtering directly
-      filters.customer_name = customer_name;
-      const response = await fetchOrders(shop_id, 0, actualLimit, filters);
-      orders = Array.isArray(response) ? response : (response.data || response.orders || []);
-    } else {
-      // Direct API fetch with filters
-      const response = await fetchOrders(shop_id, 0, actualLimit, filters);
-      orders = Array.isArray(response) ? response : (response.data || response.orders || []);
-    }
+    const response = await fetchOrders(shop_id, 0, actualLimit, filters);
+    const orders = Array.isArray(response) ? response : (response.data || response.orders || []);
 
 
     // Apply limit
     // Apply limit
     const limitedOrders = orders.slice(0, actualLimit);
     const limitedOrders = orders.slice(0, actualLimit);
@@ -396,12 +380,11 @@ async function handleListOrders(args: Record<string, any>): Promise<ToolCallResu
           count: formattedOrders.length,
           count: formattedOrders.length,
           limit: actualLimit,
           limit: actualLimit,
           filters_applied: {
           filters_applied: {
-            created_from,
-            created_to,
-            updated_from,
-            updated_to,
-            customer_email,
-            customer_name,
+            createdAtMin,
+            createdAtMax,
+            updatedAtMin,
+            updatedAtMax,
+            email,
             status
             status
           },
           },
           orders: formattedOrders
           orders: formattedOrders
@@ -579,7 +562,7 @@ async function handleToolCall(params: ToolCallParams): Promise<ToolCallResult> {
         content: [{
         content: [{
           type: 'text',
           type: 'text',
           text: JSON.stringify({
           text: JSON.stringify({
-            error: 'This tool has been removed. Use shoprenter_list_orders with customer_email filter instead.'
+            error: 'This tool has been removed. Use shoprenter_list_orders with email filter instead.'
           })
           })
         }],
         }],
         isError: true
         isError: true