# Hacker News Scraper: Stories, Comments & Who is Hiring (`lepidata/hacker-news`) Actor

Get Hacker News stories, comments and monthly "Who is hiring" posts from the official HN APIs. Optionally return only items that are new since your last run.

- **URL**: https://apify.com/lepidata/hacker-news.md
- **Developed by:** [Lepi Data](https://apify.com/lepidata) (community)
- **Categories:** Developer tools, Jobs
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.20 / 1,000 item results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## Hacker News Scraper: Stories, Comments & Who is Hiring

**What it does.** Pulls Hacker News content from the official APIs: Top, New, Best, Ask HN, Show HN and Job story lists, keyword search over stories, all comments of one story, and top-level posts from the monthly "Ask HN: Who is hiring?" thread. With **Only items new since last run** on, the tool remembers the highest item id it returned for each mode and query, and skips older items next time. That makes it easy to schedule.

**Input** (from `.actor/input_schema.json`)

- `mode` (required): `top` | `new` | `best` | `ask` | `show` | `job` | `search` | `comments` | `hiring` (default `top`)
- `query`: search keyword (mode `search`)
- `storyId`: HN item id (required for `comments`; optional for `hiring`, default is the latest Who is hiring thread)
- `maxItems`: 1–5000, default 30. Maximum rows returned and paid for.
- `sinceLastRun`: boolean, default false
- `stateStoreName`: named key-value store for the since-last-run cursor, default `lepidata-hacker-news-state`

**Output fields**

- All rows: `type`, `id`, `title`, `url`, `author` (HN username), `points`, `commentsCount`, `parentId`, `storyId`, `createdAt`, `hnUrl`
- Stories and comments: `text` (as written)
- Hiring posts (`type: hiring-post`): `postText` (exactly as written), `company` (first segment of the header line), `headerLine` (header line with emails, URLs and phone numbers removed), `remote` (true/false/null)
- Free status rows (not charged): `no-new-items`, `invalid-input`, `api-error`, `free-plan-limit`, `charge-limit-reached`, each with `errorCode`/message

**Example**
Input: `{"mode":"hiring","maxItems":50,"sinceLastRun":true}`
Output row (illustrative shape): `{"type":"hiring-post","id":…,"company":"ExampleCo","headerLine":"ExampleCo | Senior Backend Engineer | Remote (US)","remote":true,"postText":"ExampleCo | Senior Backend Engineer | Remote (US) | …","author":"exampleuser","hnUrl":"https://news.ycombinator.com/item?id=…"}`
If nothing new has been posted since the last run, you get one free `no-new-items` row and are not charged.

**Data source and compliance**

- Data comes only from the official Hacker News API (Firebase) and the Algolia HN Search API. No key, no login and no page scraping.
- Post text is returned exactly as written. The tool **never extracts emails, phone numbers or real names into contact fields**, and contact-like segments are removed from `company` and `headerLine`. Usernames appear as HN shows them.
- Retries with backoff on HTTP 429 and 5xx errors.
- You are responsible for lawful use of the data.
- Free-plan accounts get up to 100 results per run.

**Pricing.** Pay per result: $0.20 per 1,000 results, flat on every plan, no start fee. Free status rows are never charged.

# Actor input Schema

## `mode` (type: `string`):

Which Hacker News data to return.

## `query` (type: `string`):

Used when mode is "search".

## `storyId` (type: `string`):

Numeric HN item id. Required for "comments"; optional for "hiring" (default: the latest Who is hiring thread).

## `maxItems` (type: `integer`):

Maximum rows to return (and pay for).

## `sinceLastRun` (type: `boolean`):

Remembers the highest item id returned per mode/query in a key-value store on your account and skips older ones next time.

## `stateStoreName` (type: `string`):

Named key-value store (on your account) for the since-last-run cursor.

## Actor input object example

```json
{
  "mode": "top",
  "maxItems": 30,
  "sinceLastRun": false,
  "stateStoreName": "lepidata-hacker-news-state"
}
```

# Actor output Schema

## `items` (type: `string`):

All rows from this run.

# 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 = {
    "mode": "top",
    "maxItems": 30
};

// Run the Actor and wait for it to finish
const run = await client.actor("lepidata/hacker-news").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 = {
    "mode": "top",
    "maxItems": 30,
}

# Run the Actor and wait for it to finish
run = client.actor("lepidata/hacker-news").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 '{
  "mode": "top",
  "maxItems": 30
}' |
apify call lepidata/hacker-news --silent --output-dataset

```

## MCP server setup

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

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/yAAJazedBSqhcTIZB/builds/UfqfjG0zO3RCn9BUT/openapi.json
