Skip to main content
Discovers NEW products from a Shopify store using hash-based change detection.
Batch 1b: This endpoint runs in parallel with Batch 1a (update-ai-site). It’s completely decoupled - no scraped content needed.

What This Endpoint Does

  1. βœ… Fetch products from Shopify /products.json
  2. βœ… Compare hash to detect changes
  3. βœ… Save NEW products to database
  4. βœ… Generate prompts for NEW products (calls generate_prompts_for_product internally)
  5. βœ… Generate /llms/{slug}.txt for NEW products (calls generate_product_llms_txt internally)
  6. βœ… Return files for combined deploy (when skip_deploy=True)

How It Works

Hash-Based Change Detection

Instead of re-processing all products every time, we use efficient change detection:
  1. products_hash - MD5 hash of sorted product handles
  2. products_snapshot - Full product list from last sync
Hash comparison:
- If hash unchanged β†’ skip entirely (no work needed)
- If hash changed β†’ compare snapshots to find NEW products only
This means we only process truly NEW products, not all products.

Request Body

FieldTypeRequiredDescription
business_idstringYesClerk org ID
skip_deploybooleanNoIf true, return files instead of deploying (default: false)

Response

{
  "status": "success",
  "products_checked": 25,
  "new_products": [
    {
      "name": "Product A",
      "entity_id": "uuid-123"
    }
  ],
  "prompts_generated": 10,
  "llms_files_deployed": 1,
  "project_name": "business-ai-site",
  "ai_site_url": "https://business.searchcompany.dev",
  "source_url": "https://mystore.com",
  "llms_files": [...]  // Only if skip_deploy=true
}

Database Updates

TableAction
entitiesInsert new products with type: "product"
promptsInsert 10 prompts per new product
ai_sitesUpdate products_hash and products_snapshot

Database Columns Used (ai_sites)

ColumnTypePurpose
products_hashTEXTMD5 hash of sorted product handles for quick comparison
products_snapshotJSONBFull product list from last sync [{handle, name, ...}]

Code Location

src/app/apis/cron/discover_products/routes.py
src/app/shared/products/discover.py  # Core Shopify product fetching logic
src/app/shared/products/generate_llms_txt.py  # LLMs generation

Internal Services Called

This endpoint internally calls these shared services:
ServicePurpose
fetch_shopify_productsFetch all products from Shopify API
save_productSave new product to entities table
generate_prompts_for_productGenerate 10 visibility prompts
generate_product_llms_txtGenerate /llms/{slug}.txt content
Why all-in-one? For the cron job, we want a single endpoint that handles the entire product discovery flow. The separate endpoints (generate-product-prompts, generate-product-llms-txt) exist for manual triggering and debugging.