Skip to content

Latest commit

Β 

History

History
301 lines (225 loc) Β· 6.29 KB

File metadata and controls

301 lines (225 loc) Β· 6.29 KB

πŸ›’ eBay Finding API Integration Guide

Last Updated: February 16, 2026, 1:36 PM EET
Status: βœ… Active & Working


βœ… Current Status

What's Configured

  • βœ… eBay Finding API integration (lib/ebay.ts)
  • βœ… Search endpoint (/api/ebay/search)
  • βœ… Environment variables in Vercel
  • βœ… Caching (1 hour server-side)
  • βœ… Error handling & fallbacks
  • βœ… TypeScript types

πŸ”‘ Environment Variables

Make sure these are set in Vercel > Settings > Environment Variables:

NEXT_PUBLIC_EBAY_APP_ID=YourAppId-YourCompany-PRD-xxxxx
NEXT_PUBLIC_EBAY_TRACKING_ID=5338903178

Note: These variables are already configured in your Vercel project.


πŸš€ How to Use

1. API Endpoint

Search by keyword:

GET https://ebay-store.vercel.app/api/ebay/search?q=laptop&limit=12

Get trending products:

GET https://ebay-store.vercel.app/api/ebay/search?trending=true

Response format:

{
  "success": true,
  "count": 12,
  "query": "laptop",
  "products": [
    {
      "id": 1000,
      "title": "Apple MacBook Pro 14\"",
      "price": 1999,
      "currency": "USD",
      "image": "https://i.ebayimg.com/...",
      "category": "Computers/Tablets & Networking",
      "affiliateLink": "https://www.ebay.com/itm/...",
      "description": "M3 Pro chip, 16GB RAM",
      "condition": "New",
      "itemId": "123456789",
      "shipping": "0.00"
    }
  ]
}

2. Use in React Components

import { useEffect, useState } from 'react';

export function EbayProducts() {
  const [products, setProducts] = useState([]);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    async function fetchProducts() {
      const response = await fetch('/api/ebay/search?q=laptop&limit=12');
      const data = await response.json();
      setProducts(data.products);
      setLoading(false);
    }
    fetchProducts();
  }, []);

  if (loading) return <div>Loading...</div>;

  return (
    <div>
      {products.map(product => (
        <div key={product.id}>{product.title}</div>
      ))}
    </div>
  );
}

3. Server-Side Fetching (App Router)

// app/deals/page.tsx
import { getEbayProducts } from '@/lib/ebay';

export default async function DealsPage() {
  const products = await getEbayProducts('iPhone 15', 12);

  return (
    <div>
      <h1>Today's Deals</h1>
      {products.map((product, i) => (
        <div key={i}>{product.title}</div>
      ))}
    </div>
  );
}

πŸ“… Daily Trending Products

The system automatically rotates trending categories by day:

Day Category
Sunday iPhone 15 Pro
Monday PlayStation 5
Tuesday Nike Air Jordan
Wednesday MacBook Pro M3
Thursday Samsung Galaxy S24
Friday Nintendo Switch OLED
Saturday Apple Watch Series 9

Usage:

import { getTrendingProducts } from '@/lib/ebay';

const trending = await getTrendingProducts();

πŸ” API Functions

getEbayProducts(keyword, maxResults)

Fetch products by search keyword.

const products = await getEbayProducts('MacBook Pro', 12);

searchMultipleKeywords(keywords, perKeyword)

Search multiple keywords and combine results.

const products = await searchMultipleKeywords(
  ['iPhone', 'iPad', 'MacBook'],
  4 // 4 results per keyword = 12 total
);

getTrendingProducts()

Get today's trending products (auto-rotates daily).

const trending = await getTrendingProducts();

⚑ Performance & Caching

Server-Side Caching

  • API responses cached for 1 hour
  • Uses Next.js revalidate: 3600
  • Reduces API calls to eBay

Client-Side Caching

// Cache for 1 hour
fetch('/api/ebay/search?q=laptop', {
  next: { revalidate: 3600 }
});

Rate Limits

  • eBay Free Tier: 5,000 calls/day
  • With caching: ~200 unique searches/day = Well within limits

πŸ› Error Handling

The system gracefully handles errors:

try {
  const products = await getEbayProducts('laptop');
  if (products.length === 0) {
    // Fallback to static products
  }
} catch (error) {
  console.error('eBay API error:', error);
  // Show cached/static products instead
}

πŸ“Š Testing the API

1. Test in Browser

Visit: https://ebay-store.vercel.app/api/ebay/search?q=laptop

You should see JSON response with products.

2. Test with cURL

curl "https://ebay-store.vercel.app/api/ebay/search?q=laptop&limit=5"

3. Check Logs

Vercel Dashboard > Deployments > [Latest] > Logs

Look for:

πŸ” Fetching from eBay API: laptop
βœ… eBay API: Found 12 items for "laptop"

πŸ”§ Troubleshooting

"App ID not configured" warning

Problem: Environment variable missing
Solution: Add NEXT_PUBLIC_EBAY_APP_ID to Vercel

API returns empty array

Problem: Invalid App ID or API error
Solution: Check App ID format and eBay Developer account status

Slow response times

Problem: No caching
Solution: Already implemented! Should be fast after first request


πŸš€ Next Steps

Already Done

  • eBay API integration
  • Search endpoint
  • Caching layer
  • Error handling
  • TypeScript types

Optional Enhancements

  • Add Redis caching (for production scale)
  • Implement eBay Browse API (more features)
  • Add price tracking
  • Create "deals" page with eBay products
  • Mix eBay + static products on homepage

πŸ“ API Documentation

Official eBay Docs:

Your Implementation:

  • Code: lib/ebay.ts
  • Endpoint: app/api/ebay/search/route.ts
  • Types: EbayProduct, EbayApiResponse

βœ… Status: READY TO USE!

Your eBay API is now:

  • βœ… Connected to Vercel environment
  • βœ… Cached for performance
  • βœ… Error-resistant with fallbacks
  • βœ… Typed with TypeScript
  • βœ… Ready for production!

Test it now: https://ebay-store.vercel.app/api/ebay/search?trending=true


Questions? Check the code or test the endpoints above! πŸš€