# Substack Scraper (`mambalabs/substack-scraper`) Actor

Scrape Substack publications and posts: subscriber count, paid plan prices, author, and every post with date, paid flag, likes, comments, restacks, authors, and tags. Search Substack by keyword for posts or the newsletters behind them. Public data, no login. Clay ready.

- **URL**: https://apify.com/mambalabs/substack-scraper.md
- **Developed by:** [Mamba Labs](https://apify.com/mambalabs) (community)
- **Categories:** Lead generation, Social media, News
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.98 / 1,000 post rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Substack Scraper

Scrape Substack publications and posts, or search all of Substack by keyword. For each publication you get its name, author, subscriber count as Substack shows it, paid plan prices, and its newest posts. Each post row carries the date, the paid or free flag, likes, comments, restacks, word count, bylines, and tags. A search returns the matching posts, or one row per newsletter behind them, which turns a topic into a list of newsletters to pitch, sponsor, or study. Rows are flat, so they export to CSV or drop into a Clay table.

### Features

- **Publication profile.** Name, author, tagline, language, first post date, the subscriber count Substack prints on the homepage (Over 1,200,000 subscribers) or its rounded figure (1.3K+), Substack's subscriber tier text, and the monthly, yearly, and founding plan prices.
- **Every post as a row.** Title, subtitle, URL, publish time, `audience` (free, paid, or founding), word count, likes, comments, restacks, bylines with guest writers, and tags. Optional post text, where a paid post gives its free preview.
- **Search Substack.** Keyword search across Substack posts, with each post's publication and subscriber count on the same row. Set Search output to publications for one row per newsletter instead.
- **Any address works.** Custom domains (lennysnewsletter.com), substack.com subdomains, profile links (substack.com/@lenny), or a bare name (lenny).
- **Date window.** Keep only posts from the last N days.

### How it reads Substack

Substack's public pages and the public JSON routes its own site uses: the publication homepage, the post archive, and post search. robots.txt is read for every host and checked before every request. No login, no account, no API key, and no other developer's actor. A host that refuses a direct request is retried through the Apify proxy.

### Input

| Field | Type | Default | What it does |
|---|---|---|---|
| `publications` | array | | Up to 100 publications: a URL, a domain, a substack.com profile, or a bare Substack name |
| `search_queries` | array | | Up to 20 keyword searches across Substack posts |
| `search_output` | string | `posts` | `posts` for one row per matching post, `publications` for one row per newsletter behind them |
| `max_posts_per_publication` | string | `20` | Newest posts per publication, 0 to 1000. 0 returns only the publication row |
| `max_search_results` | string | `50` | Rows per search query, 1 to 1000 |
| `since_days` | string | `0` | Skip posts older than this many days. 0 keeps all |
| `include_publication_row` | string | `true` | `false` returns post rows only |
| `include_body` | string | `false` | `true` adds the post text to each post row of a listed publication |
| `max_charge_usd` | string | | The run stops before it would charge more than this |
| `proxy_mode` | string | `auto` | `auto` (direct, then the Apify proxy for a host that refuses) or `direct` |

Every scalar input is accepted as a string, which is what Clay sends.

### Output

One row layout for every row type, so no column is lost between them. Key fields:

| Field | Rows | Example |
|---|---|---|
| `row_type` | all | `publication`, `post`, `no_results`, `error` |
| `publication_name`, `publication_url`, `author_name` | all | `Lenny's Newsletter`, `https://www.lennysnewsletter.com`, `Lenny Rachitsky` |
| `subscriber_count_text`, `subscriber_count_min` | all | `Over 1,200,000 subscribers`, `1200000` |
| `subscriber_tier_text`, `paid_subscriber_tier_text` | all | `Millions of subscribers`, `Tens of thousands of paid subscribers` |
| `has_paid_plan`, `monthly_price`, `yearly_price`, `founding_price`, `price_currency` | all | `true`, `20`, `200`, `400`, `USD` |
| `post_title`, `post_url`, `post_date`, `post_type` | post | `How to tell if a startup has a moat`, `newsletter` |
| `audience`, `is_paid` | post | `only_paid`, `true` |
| `reaction_count`, `comment_count`, `restack_count`, `wordcount` | post | `372`, `2`, `21`, `4153` |
| `post_authors`, `post_tags`, `post_excerpt`, `body_text` | post | `Dan Hockenmaier`, `Career` |
| `search_query` | search rows | `cold email` |
| `row_status`, `error_reason`, `billable_events_json` | all | `ok`, `null`, `{"post-row":1}` |

`subscriber_count_min` is the lower bound of what Substack shows (1.3K+ reads as 1300), not an exact count. A publication that hides its count leaves both subscriber fields empty.

The run summary (key-value store record `RUN_SUMMARY`) lists each publication and search with its row count and any note.

### Pricing

Pay per event. You pay only these events; the Apify platform and proxy costs of your run are paid by Mamba Labs.

| Event | Free plan | Bronze | Silver | Gold |
|---|---|---|---|---|
| Post row (`post-row`), one post | $0.00115 | $0.001093 | $0.001035 | $0.000977 |
| Publication row (`publication-row`), one publication profile | $0.002 | $0.0019 | $0.0018 | $0.0017 |
| Actor start (`apify-actor-start`), once per run | $0.001057 | $0.001057 | $0.001057 | $0.001057 |

Free rows: `no_results` and `error` rows, including the row a refused input returns. On the Apify free plan the actor stops at 1.50 USD of evaluation a month (about 1304 post rows); any paid Apify plan removes that cap.

Example: 10 publications with their 20 newest posts each is 10 publication rows ($0.02) plus 200 post rows ($0.23), $0.251 with the actor start.

### Usage examples

#### Apify Console or API

```json
{ "publications": ["lenny.substack.com", "https://www.notboring.co"], "max_posts_per_publication": "20" }
```

```json
{ "search_queries": ["b2b marketing", "cold email"], "search_output": "publications", "max_search_results": "100" }
```

```json
{ "publications": ["lenny"], "since_days": "30", "include_body": "true" }
```

#### Clay

Add an Apify column that sends a newsletter URL in `publications` with `max_posts_per_publication` set to `0`, and read `subscriber_count_min`, `has_paid_plan`, and `monthly_price` from the publication row.

#### MCP

The MCP server `@mambalabsdev/mcp-substack-scraper` exposes this actor as a tool for Claude and other MCP clients.

### Error handling

| Situation | What you get |
|---|---|
| The input has no publication and no query, or a value that cannot be read | One free row, `row_status` `error`, `error_reason` starting with `input_invalid:`. The run ends successfully and nothing is charged by this actor beyond the actor start |
| A site that is not a Substack publication | One free `error` row saying so |
| A publication refuses every route, or robots.txt disallows it | One free `error` row with `row_status` `blocked` |
| A search with no match | One free `no_results` row |
| Max charge reached | The run stops before the next billable row |

### Limitations

- Subscriber counts are what Substack chooses to show: an exact homepage figure for some publications, a rounded figure (1.3K+) for others, and nothing for publications that hide it.
- Paid posts give only the free preview Substack shows to visitors.
- Substack search ranks by its own relevance and returns at most about 1,000 posts per query.
- Notes, comments text, and subscriber lists are not read.
- You are responsible for how you use the data and for Substack's terms.

### More from Mamba Labs

| Actor | Actor ID |
|---|---|
| [Account Hiring Watch](https://apify.com/mambalabs/account-hiring-watch?fpr=mamba) | `gRAZA5WBi1r6L0gy7` |
| [Agent Accessibility Auditor](https://apify.com/mambalabs/agent-accessibility-auditor?fpr=mamba) | `anxbRv0lKrpQ1pnua` |
| [Agent to Brokerage Resolver](https://apify.com/mambalabs/agent-brokerage-resolver?fpr=mamba) | `ePRRGLxOGyaVHO4dI` |
| [AI Tooling Detector](https://apify.com/mambalabs/ai-tooling-detector?fpr=mamba) | `EwkHhmqiuJgRoVEbE` |
| [B2B Reddit Conversation Monitor](https://apify.com/mambalabs/b2b-reddit-conversation-monitor?fpr=mamba) | `SoDryzzsjmY3SsiyG` |
| [Bluesky Brand Presence Mapper](https://apify.com/mambalabs/bluesky-brand-presence-mapper?fpr=mamba) | `eLpxzP4IuXznlFVND` |
| [Career Change Signal Engine](https://apify.com/mambalabs/career-change-signal-engine?fpr=mamba) | `vX2Yga1a6wGaXaP14` |
| [Company Change Event Feed](https://apify.com/mambalabs/company-change-event-feed?fpr=mamba) | `oX44rS0fkEJ3rXLWe` |
| [Company Contact Details Extractor](https://apify.com/mambalabs/company-contact-details-extractor?fpr=mamba) | `4mMncKaJykiq94grz` |
| [Company Discovery List Builder](https://apify.com/mambalabs/company-discovery-list-builder?fpr=mamba) | `jch0HdaZnpbMqlcGS` |
| [Company Firmographic Enricher](https://apify.com/mambalabs/company-firmographic-enricher?fpr=mamba) | `YlUtLWjfPpqykmB8g` |
| [Company Funding Record](https://apify.com/mambalabs/funding-investor-record?fpr=mamba) | `OFS4Mt1gyYNtGfUbE` |
| [Company Headcount Estimator](https://apify.com/mambalabs/company-headcount-estimator?fpr=mamba) | `aHC4GROnNt6kfZe5r` |
| [Company Identity Resolver](https://apify.com/mambalabs/company-identity-resolver?fpr=mamba) | `lr8fTRAmZCBZmuwwh` |
| [Company Social Presence Mapper](https://apify.com/mambalabs/company-social-presence-mapper?fpr=mamba) | `4k6CCemkgBDz18m2h` |
| [Competitor Price, Stock, and Changelog Monitor](https://apify.com/mambalabs/competitor-price-stock-changelog-monitor?fpr=mamba) | `yxdgCbUQ4PYQWwRNU` |
| [Contact Classifier](https://apify.com/mambalabs/contact-classifier?fpr=mamba) | `0lGSeYJmniXhGANnO` |
| [Contractor License Lookup](https://apify.com/mambalabs/contractor-license-lookup?fpr=mamba) | `WBYK3CPI2kdeq4bP1` |
| [Cookie Consent Audit](https://apify.com/mambalabs/cookie-consent-audit?fpr=mamba) | `TrKyOS0KBoGC35nbr` |
| [Domain Deliverability Checker](https://apify.com/mambalabs/domain-deliverability-checker?fpr=mamba) | `0tVgxI7A6o9jMlxmc` |
| [Domain to LinkedIn URL Resolver](https://apify.com/mambalabs/domain-to-linkedin-url-resolver?fpr=mamba) | `3HtnSaqPHOg1Qg5gx` |
| [Ecommerce Platform Profiler](https://apify.com/mambalabs/ecommerce-platform-profiler?fpr=mamba) | `5G2NeYjBbQTjaTn9L` |
| [Ecommerce Store Discovery](https://apify.com/mambalabs/ecommerce-store-discovery?fpr=mamba) | `PeHu4sLyFvQHXUUrX` |
| [Event Presence Index](https://apify.com/mambalabs/event-presence-index?fpr=mamba) | `WLhMy8fMDgsxdYxv5` |
| [Expert Witness Directory](https://apify.com/mambalabs/expert-witness-directory?fpr=mamba) | `LIpwlgfE3LaQBaXd4` |
| [Funding and Press Signal Scanner](https://apify.com/mambalabs/funding-press-signal-scanner?fpr=mamba) | `FS13X6dhQVgX3XOM6` |
| [GitHub Organization Signal Scanner](https://apify.com/mambalabs/github-organization-signal-scanner?fpr=mamba) | `ahF8RRpv5mzPao5CN` |
| [Google Ads Transparency Monitor](https://apify.com/mambalabs/google-ads-transparency-monitor?fpr=mamba) | `1eOwxhBVxzvOXAm4s` |
| [Government Contract Award Monitor](https://apify.com/mambalabs/public-award-monitor?fpr=mamba) | `zhEtllASykOcx9hJ8` |
| [GTM Hiring Signal Scraper](https://apify.com/mambalabs/gtm-hiring-signal-scraper?fpr=mamba) | `D7O1SA2EqwHGsGr1P` |
| [GTM Signals Aggregator](https://apify.com/mambalabs/b2b-buying-signals-hiring-tech-stack-intent-for-clay?fpr=mamba) | `xKdRfnfFNkdMpFuNs` |
| [ICP Fit Scorer](https://apify.com/mambalabs/icp-account-lead-scoring-fit-scorer-0-100-for-clay?fpr=mamba) | `W161DT8W4kW55dMFh` |
| [Influencer Change Monitor](https://apify.com/mambalabs/creator-change-monitor?fpr=mamba) | `d2VVgahNL6UmcLkhg` |
| [Influencer Finder](https://apify.com/mambalabs/creator-finder?fpr=mamba) | `tpkedmloIIWtXx6sg` |
| [Influencer Lead List Builder](https://apify.com/mambalabs/creator-lead-list-all-in-one?fpr=mamba) | `KnmByszcv135yM30G` |
| [Influencer Profile Scraper](https://apify.com/mambalabs/creator-profile-reader?fpr=mamba) | `EqEnklDVMIcB1V499` |
| [Influencer Talent Agency Lookup](https://apify.com/mambalabs/talent-agency-lookup?fpr=mamba) | `zCuX4Mgyg6JvXgGzd` |
| [Instagram Facebook Brand Presence Mapper](https://apify.com/mambalabs/meta-brand-presence-mapper?fpr=mamba) | `HXh65I0JBjPsunbY8` |
| [Integration and Marketplace Presence Mapper](https://apify.com/mambalabs/integration-marketplace-presence-mapper?fpr=mamba) | `V0guNuvM85Q61f2gj` |
| [Job Board Keyword Signal Scanner](https://apify.com/mambalabs/job-board-keyword-signal-scanner?fpr=mamba) | `4DvqpvhMR74NLcDDY` |
| [Job Change Tracker](https://apify.com/mambalabs/job-change-tracker?fpr=mamba) | `L8UbEmMJC1XYPSZOb` |
| [Job Posting Monitor](https://apify.com/mambalabs/gtm-job-discovery?fpr=mamba) | `QCfICD9kOPiOdj5iI` |
| [Legal Entity Resolver](https://apify.com/mambalabs/legal-entity-resolver?fpr=mamba) | `KHFyPCDIx7CyqULYm` |
| [Link in Bio Scraper and Newsletter Detector](https://apify.com/mambalabs/link-in-bio-newsletter-checker?fpr=mamba) | `OorucdheTIgu7RFzK` |
| [LinkedIn Company Page Mapper](https://apify.com/mambalabs/linkedin-company-presence-mapper?fpr=mamba) | `zOPm6A9JEhUGcIdFW` |
| [LinkedIn Post Tracker](https://apify.com/mambalabs/linkedin-post-engager-capture?fpr=mamba) | `oiGLNPuaf5BRaz9K5` |
| [Local Business Lead Builder](https://apify.com/mambalabs/local-business-lead-builder?fpr=mamba) | `qMN97aoHhsAS5bznV` |
| [Local Rank and Map Pack Tracker](https://apify.com/mambalabs/local-rank-map-pack-tracker?fpr=mamba) | `gv0kyHGDIg8XscclB` |
| [Lookalike Company Finder](https://apify.com/mambalabs/lookalike-company-finder?fpr=mamba) | `e2O426WBAbLLQL4Z2` |
| [Manufacturer and Supplier Finder](https://apify.com/mambalabs/manufacturer-supplier-finder?fpr=mamba) | `Qcsdmd0lUfPzVkonh` |
| [Meta Ad Library Monitor](https://apify.com/mambalabs/meta-ad-library-monitor?fpr=mamba) | `J1GWlSXfSGU3u8Wng` |
| [Mobile Phone Waterfall](https://apify.com/mambalabs/mobile-phone-waterfall-orchestrator?fpr=mamba) | `6OOgPktf7RIa5XCOP` |
| [New Company Registrations Feed](https://apify.com/mambalabs/new-company-registrations-feed?fpr=mamba) | `g2WfZhWvCtc57g2Jo` |
| [New Hire Finder](https://apify.com/mambalabs/new-hire-finder?fpr=mamba) | `cKuc38p4nYHNF3IW8` |
| [Newsletter Sponsor Tracker](https://apify.com/mambalabs/newsletter-sponsor-tracker?fpr=mamba) | `qSwpqxD1TiPZpLQHv` |
| [Open Tender and RFP Finder](https://apify.com/mambalabs/open-tender-rfp-finder?fpr=mamba) | `kPTGz6t6TFoUUyfaO` |
| [Outbound Stack Detector](https://apify.com/mambalabs/outbound-infrastructure-fingerprint?fpr=mamba) | `v43UJC8r7qW7cBSTG` |
| [Page Finder and Extractor](https://apify.com/mambalabs/page-finder-extractor?fpr=mamba) | `TpurgcOZbVnknlaiC` |
| [Partner and Member Directory Extractor](https://apify.com/mambalabs/partner-member-directory-extractor?fpr=mamba) | `ZX0XJPPUvnFJxeC1a` |
| [People Finder & Email Verifier](https://apify.com/mambalabs/people-finder?fpr=mamba) | `LEgloG7tWgQl4o6TD` |
| [Person LinkedIn URL Resolver](https://apify.com/mambalabs/person-linkedin-url-resolver?fpr=mamba) | `ssuyPV8LnEsL8qbnb` |
| [Person Social Footprint Mapper](https://apify.com/mambalabs/person-social-footprint-mapper?fpr=mamba) | `jfQXa2zW9FHCJot9K` |
| [Personal Email to Company Resolver](https://apify.com/mambalabs/personal-email-to-company-resolver?fpr=mamba) | `AefT5Ye6YNPFQwJBf` |
| [Pinterest Brand Presence Mapper](https://apify.com/mambalabs/pinterest-brand-presence-mapper?fpr=mamba) | `d1HvjZfKhgvWsoEwn` |
| [Podcast Guest and Host Finder](https://apify.com/mambalabs/podcast-guest-host-finder?fpr=mamba) | `o2MGSvgbSLeeXOsIo` |
| [Prospect Engine](https://apify.com/mambalabs/b2b-prospect-engine?fpr=mamba) | `q9rT6v64nUJdPexOQ` |
| [Public Feature Board and Roadmap Monitor](https://apify.com/mambalabs/public-feature-board-roadmap-monitor?fpr=mamba) | `rcHF5gj5r2Vqnry35` |
| [Publishing Frequency Tracker](https://apify.com/mambalabs/blog-publishing-frequency?fpr=mamba) | `TbLwaUUATdYb6wp4N` |
| [Reddit Brand Presence Mapper](https://apify.com/mambalabs/reddit-brand-presence-mapper?fpr=mamba) | `pKQZmDaT70SEb54bZ` |
| [Reporting Window Finder](https://apify.com/mambalabs/public-company-reporting-window-finder?fpr=mamba) | `uINxR7a1IW8qUTRUX` |
| [Sequencer Event Poller](https://apify.com/mambalabs/sequencer-event-poller?fpr=mamba) | `S6s8Rjd61tGdrMRk4` |
| [Sequencer Lead Push](https://apify.com/mambalabs/clay-to-instantly-smartlead-push?fpr=mamba) | `0Jv27VeWM5tSZQs9x` |
| [Team Page People Extractor](https://apify.com/mambalabs/team-page-people-extractor?fpr=mamba) | `j8a9zX0k4mNbvDbWK` |
| [Tech Stack Signal Detector](https://apify.com/mambalabs/gtm-tech-stack-signal-scraper?fpr=mamba) | `qyd7nNyqFPelQViBx` |
| [TikTok Brand Presence Mapper](https://apify.com/mambalabs/tiktok-brand-presence-mapper?fpr=mamba) | `fco8FvoJcSafbeyd1` |
| [Trustpilot Reputation Enricher](https://apify.com/mambalabs/review-platform-reputation-enricher?fpr=mamba) | `3lIqfCt61j4hqE1xz` |
| [VC and Accelerator Portfolio List Builder](https://apify.com/mambalabs/vc-accelerator-portfolio-list-builder?fpr=mamba) | `chH8hrfuoqqolW06m` |
| [WCAG Accessibility Audit](https://apify.com/mambalabs/wcag-accessibility-audit?fpr=mamba) | `P3jBj3FRghKEhX52z` |
| [Website Phrase and Business Model Classifier](https://apify.com/mambalabs/website-phrase-business-model-classifier?fpr=mamba) | `CBuZ9k7sRwBeiKiCS` |
| [Website Traffic Rank Estimator](https://apify.com/mambalabs/website-traffic-rank-estimator?fpr=mamba) | `GnOFUzlNVIoXgeJjH` |
| [Work Email Waterfall](https://apify.com/mambalabs/email-waterfall-orchestrator?fpr=mamba) | `OT6xqTFThC0Rjf7Zj` |
| [Workplace Program Detector](https://apify.com/mambalabs/workplace-program-detector?fpr=mamba) | `Li6pPDhqbdzFz3h7G` |
| [X Brand Presence Mapper](https://apify.com/mambalabs/x-brand-presence-mapper?fpr=mamba) | `oLOgadhHUkNAyDA3w` |
| [YouTube Channel Stats Extractor](https://apify.com/mambalabs/youtube-channel-transcript-extractor?fpr=mamba) | `6hSpD3kd2s2IQ4VSs` |

Built by [Mamba Labs](https://apify.com/mambalabs?fpr=mamba).

# Actor input Schema

## `publications` (type: `array`):

Substack publications, one per line, up to 100: a URL (https://www.lennysnewsletter.com), a domain (lenny.substack.com), a profile (substack.com/@lenny), or a bare Substack name (lenny). Each one returns a publication row and its newest posts.

## `search_queries` (type: `array`):

Keywords to search across Substack posts, one per line, up to 20. Each query returns matching posts, or the publications behind them when Search output is publications.

## `search_output` (type: `string`):

What a search query returns.

## `max_posts_per_publication` (type: `string`):

Newest posts returned per publication, 0 to 1000. 0 returns only the publication row.

## `max_search_results` (type: `string`):

Rows returned per search query, 1 to 1000.

## `since_days` (type: `string`):

Optional. Skip posts older than this many days. 0 or empty keeps every post up to the max.

## `include_publication_row` (type: `string`):

true to return one publication row per listed publication (name, author, subscribers, paid plan prices), billed as a publication row. false returns only post rows.

## `include_body` (type: `string`):

true to add the post text (up to 20,000 characters) to each post row of a listed publication. A paid post gives its free preview. Reads one more page per post; no extra charge.

## `max_charge_usd` (type: `string`):

Optional. The run stops before it would charge more than this.

## `proxy_mode` (type: `string`):

How pages are fetched.

## `source_tag` (type: `string`):

Internal attribution tag. Leave empty.

## Actor input object example

```json
{
  "publications": [
    "lenny.substack.com"
  ],
  "search_queries": [
    "cold email"
  ],
  "search_output": "posts",
  "max_posts_per_publication": "5",
  "max_search_results": "5",
  "since_days": "0",
  "include_publication_row": "true",
  "include_body": "false",
  "proxy_mode": "auto"
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `run_summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "publications": [
        "lenny.substack.com"
    ],
    "search_queries": [
        "cold email"
    ],
    "max_posts_per_publication": "5",
    "max_search_results": "5"
};

// Run the Actor and wait for it to finish
const run = await client.actor("mambalabs/substack-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "publications": ["lenny.substack.com"],
    "search_queries": ["cold email"],
    "max_posts_per_publication": "5",
    "max_search_results": "5",
}

# Run the Actor and wait for it to finish
run = client.actor("mambalabs/substack-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "publications": [
    "lenny.substack.com"
  ],
  "search_queries": [
    "cold email"
  ],
  "max_posts_per_publication": "5",
  "max_search_results": "5"
}' |
apify call mambalabs/substack-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,mambalabs/substack-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/UEFsdwiPLmPNVy9xd/builds/aBvnjwGcsyjYIt3cb/openapi.json
