MarsX-dev / seobot

https://seobotai.com
1 stars 2 forks source link

API Pagination Returns Incomplete Results Despite Reporting Higher Total #2

Closed jacob-dietle closed 20 hours ago

jacob-dietle commented 21 hours ago

The SEObot API's pagination appears to be inconsistent with the reported total number of articles. The API consistently returns 4 fewer articles than the reported total.

Steps to Reproduce

  1. Initialize SEObot client with valid API key
  2. Call getArticles() with pagination (limit=4)
  3. Continue paginating until no more articles are returned

Current Behavior

Expected Behavior

Either:

Logs

> nextjs@0.1.0 dev
> next dev

   ▲ Next.js 14.1.0
   - Local:        http://localhost:3000
   - Environments: .env

 ✓ Ready in 1761ms
 ✓ Compiled /middleware in 180ms (135 modules)
 ○ Compiling /blog ...
 ✓ Compiled /blog in 2.4s (686 modules)
 ✓ Compiled in 647ms (307 modules)
 ⚠ The "images.domains" configuration is deprecated. Please use "images.remotePatterns" configuration instead.
 ✓ Compiled /not-found in 215ms (678 modules)
SEObot client initialized
getAllPosts called: { page: 1, limit: 20, initialized: false }
Initializing post cache...
Fetching SEObot page 1
SEObot page 1: {
  received: 4,
  total: 16,
  raw: { articles: [ [Object], [Object], [Object], [Object] ], total: 16 }
}
Progress: {
  page: 1,
  receivedThisPage: 4,
  totalReceived: 4,
  expectedTotal: 16,
  remaining: 12
}
Fetching SEObot page 2
SEObot page 2: {
  received: 4,
  total: 16,
  raw: { articles: [ [Object], [Object], [Object], [Object] ], total: 16 }
}
Progress: {
  page: 2,
  receivedThisPage: 4,
  totalReceived: 8,
  expectedTotal: 16,
  remaining: 8
}
Fetching SEObot page 3
SEObot page 3: {
  received: 4,
  total: 16,
  raw: { articles: [ [Object], [Object], [Object], [Object] ], total: 16 }
}
Progress: {
  page: 3,
  receivedThisPage: 4,
  totalReceived: 12,
  expectedTotal: 16,
  remaining: 4
}
Fetching SEObot page 4
SEObot page 4: { received: 0, total: 16, raw: { articles: [], total: 16 } }
Empty page 4, empty count: 1
Fetching SEObot page 5
SEObot page 5: { received: 0, total: 16, raw: { articles: [], total: 16 } }
Empty page 5, empty count: 2
Fetching SEObot page 6
SEObot page 6: { received: 0, total: 16, raw: { articles: [], total: 16 } }
Empty page 6, empty count: 3
Stopping pagination: { emptyPages: 3, totalReceived: 12, expectedTotal: 16 }
Cache initialization complete: {
  totalSeobotPosts: 12,
  expectedTotal: 12,
  posts: [
    {
      slug: 'understanding-how-vineyard-management-companies-work-with-vineyards-a-crash-course',
      title: 'Understanding how Vineyard Management Companies work with Vineyards: A Crash Course'
    },
    {
      slug: 'ultimate-guide-to-iot-soil-sensors-in-vineyards',
      title: 'Ultimate Guide to IoT Soil Sensors in Vineyards'
    },
    {
      slug: 'smart-monitoring-systems-for-vineyards',
      title: 'Smart Monitoring Systems for Vineyards'
    },
    {
      slug: 'developing-buyer-personas-for-wine-sales',
      title: 'Developing Buyer Personas for Wine Sales'
    },
    {
      slug: 'what-do-vineyard-operators-look-for-in-agtech-purchasing-cycles',
      title: 'What do Vineyard Operators look for in Agtech Purchasing Cycles?'
    },
    {
      slug: '2025-wine-industry-contact-management-checklist',
      title: '2025 Wine Industry Contact Management Checklist'
    },
    {
      slug: 'common-pitfalls-selling-to-the-wine-industry-what-to-know',
      title: 'Common pitfalls selling to the Wine Industry: What to Know'
    },
    {
      slug: 'how-to-sell-to-vineyards-and-vineyard-management-companies-as-an-agtech-company',   
      title: 'How to Sell to Vineyards & Vineyard Management Companies as an Agtech Company'     
    },
    {
      slug: '10-ways-to-verify-wine-industry-contact-data',
      title: '10 Ways to Verify Wine Industry Contact Data'
    },
    {
      slug: 'guide-finding-reliable-vineyard-supplier-contacts',
      title: 'Guide: Finding Reliable Vineyard Supplier Contacts'
    },
    {
      slug: 'top-5-vineyard-management-software-tools-compared',
      title: 'Top 5 Vineyard Management Software Tools Compared'
    },
    {
      slug: 'ai-in-vineyard-disease-forecasting',
      title: 'AI in Vineyard Disease Forecasting'
    }
  ]
}
Markdown posts loaded: 0
Total combined posts: 12
Pagination results: {
  page: 1,
  start: 0,
  end: 20,
  total: 12,
  returnedPosts: 12,
  hasMore: false
}
getAllPosts called: { page: 1, limit: 20, initialized: true }
Markdown posts loaded: 0
Total combined posts: 12
Pagination results: {
  page: 1,
  start: 0,
  end: 20,
  total: 12,
  returnedPosts: 12,
  hasMore: false
}

Thanks!

vitalikmay commented 20 hours ago

The pagination is zero-based, meaning page numbers start at 0 rather than 1. To get all 16 articles, use pages 0-3 instead of 1-4.

jacob-dietle commented 17 hours ago

Always the simplest thing - sorry lol and thanks!