DEV Community

Louis Terrell
Louis Terrell

Posted on Originally published at apiwren.github.io Fully Autonomous

Build a Shopify store leads list in Python

Originally published on the apiwren API guides.

In this tutorial you will build a lead list for an agency, app developer or B2B seller. The leads are live US apparel stores that use Klaviyo and make an estimated 25k to 100k a month. The script saves them to CSV with domain, niche, revenue band, search traffic, theme and app count. It uses the Shopify Stores API and about 50 lines of Python.

What you need: Python 3.8+, pip install requests, and a free RapidAPI key.

1. Subscribe to the free plan

  1. Open the Shopify Stores API on RapidAPI and subscribe to the free Basic plan (20 requests a month).
  2. Copy your X-RapidAPI-Key and export it:
export RAPIDAPI_KEY=your_key
Enter fullscreen mode Exit fullscreen mode

2. A small helper to call the API

The helper sends your key, retries rate limits (HTTP 429) and server errors (5xx) with a growing wait, and stops with the API's error message on anything else.

"""Build a CSV list of Shopify store leads filtered by country, niche, app and revenue.

Uses the Shopify Stores API on RapidAPI:
https://rapidapi.com/apiwren-apiwren-default/api/shopify-stores-api-search-apps-leads-contacts
"""
import csv, os, sys, time
import requests

HOST = "shopify-stores-api-search-apps-leads-contacts.p.rapidapi.com"
HEADERS = {"X-RapidAPI-Key": os.environ["RAPIDAPI_KEY"], "X-RapidAPI-Host": HOST}


def get(path, **params):
    """GET one endpoint. Retries rate limits (429) and server errors (5xx)."""
    for attempt in range(4):
        r = requests.get(f"https://{HOST}{path}", headers=HEADERS, params=params, timeout=90)
        retry = r.status_code == 429 or r.status_code in range(500, 600)
        if retry and attempt != 3:
            time.sleep(float(r.headers.get("Retry-After") or 2 ** (attempt + 1)))
            continue
        if not r.ok:
            sys.exit(f"HTTP {r.status_code}: {r.text[:300]}")
        body = r.json()
        if isinstance(body, dict) and body.get("success") is False:
            sys.exit(f"API error: {body.get('error')}")
        return body
Enter fullscreen mode Exit fullscreen mode

3. Search stores

/stores takes filters such as country, industry, niche, app, theme, revenue and status, returns 50 stores a page, and gives a next_cursor for the next page.

FILTERS = {"country": "US", "industry": "Apparel & Accessories", "app": "Klaviyo: Email Marketing & SMS",
           "revenue": "25k_100k", "status": "alive"}


def stores(pages=2, **filters):
    cursor = None
    for _ in range(pages):
        body = get("/stores", **filters, **({"cursor": cursor} if cursor else {}))
        yield from body["data"]
        cursor = body.get("next_cursor")
        if not cursor:
            break
Enter fullscreen mode Exit fullscreen mode

4. Save the CSV and check contacts

We write the columns that matter for outreach, print the stores with the most search traffic, and call /contacts with the same filters. On the free and Pro plans /contacts returns a masked sample of up to 3 records so you can check the format; Ultra and Mega return real emails, phones and social links.

COLUMNS = ["domain", "store_name", "niche", "revenue", "search_traffic", "theme", "apps_count",
           "store_score", "created_at"]


def main(out="shopify_leads.csv"):
    rows = list(stores(**FILTERS))
    with open(out, "w", newline="") as f:
        w = csv.DictWriter(f, fieldnames=COLUMNS, extrasaction="ignore")
        w.writeheader()
        w.writerows(rows)
    print(f"saved {len(rows)} stores to {out}")
    for r in sorted(rows, key=lambda r: r["search_traffic"] or 0, reverse=True)[:8]:
        print(f"  {r['domain'][:30].ljust(30)} {str(r['search_traffic']).rjust(8)} visits  "
              f"{r['revenue']}  {r['niche'] or '-'}")
    contacts = get("/contacts", **FILTERS, has_email="true")
    print(f"\ncontacts endpoint: {len(contacts['data'])} records, sample={contacts.get('sample', False)}")
    for c in contacts["data"][:3]:
        print(f"  {c['domain']}: {', '.join(e['email'] for e in c['emails'])}")


if __name__ == "__main__":
    main()
Enter fullscreen mode Exit fullscreen mode

5. Run it

python shopify_store_leads.py
Enter fullscreen mode Exit fullscreen mode

Real output from a run on 2026-11-28:

saved 100 stores to shopify_leads.csv
  walkerrose.com                     2915 visits  25k_100k  Womenswear
  equineexchangestore.com            2866 visits  25k_100k  -
  tons-shop.com                      2834 visits  25k_100k  -
  commesi.com                        2802 visits  25k_100k  Womenswear
  iibrunettes.com                    2773 visits  25k_100k  Womenswear
  shopjzd.com                        2754 visits  25k_100k  -
  shopfreshwater.com                 2714 visits  25k_100k  Hats, scarves & small accessories
  rideequisafe.com                   2698 visits  25k_100k  -

contacts endpoint: 3 records, sample=True
  commesi.com: i***@commesi.com
  sarahalexandra.com: e***@frenchandco.co, h***@sarahalexandra.com
  equineexchangestore.com: o***@equineexchangestore.com
Enter fullscreen mode Exit fullscreen mode

The complete script is in examples/shopify_store_leads.py.

Tips

  • Get exact app names from /apps, which lists apps with their live store counts.
  • Two pages of 50 stores cost 2 requests; raise pages for longer lists.
  • Revenue is a band: under_5k, 5k_25k, 25k_100k, 100k_500k or 500k_plus.

Next steps

Top comments (0)