Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

substack-api

jakub-k-slys223MIT0.6.0TypeScript support: included

TypeScript API client for interacting with Substack webservice

substack, api, client, typescript

readme

Substack API

npm version Documentation Status License: MIT TypeScript

A TypeScript client for interacting with the Substack webservice API. This library provides a clean, type-safe interface to fetch publication details, posts, comments, and perform searches across Substack publications.

Features

  • 🔍 Publication Management - Fetch publication details and metadata
  • 📝 Post Operations - Get posts, search by criteria, and access individual posts
  • 💬 Comment System - Retrieve comments and comment threads
  • 📄 Pagination Support - Built-in pagination for all list operations
  • 🛡️ TypeScript First - Full type safety with comprehensive type definitions
  • Error Handling - Comprehensive error handling with custom error types
  • 🔧 Configurable - Support for different API versions and custom configurations

Quick Start

Install the package:

npm install substack-api

Basic usage:

import { Substack } from 'substack-api';

// Create a client for a specific publication
const client = new Substack({
  hostname: 'example.substack.com'
});

// Fetch recent posts
const posts = await client.getPosts({ limit: 5 });

// Search for posts
const results = await client.searchPosts({
  query: 'typescript',
  type: 'newsletter'
});

Documentation

📚 Read the full documentation →

The documentation includes:

Testing

The project includes comprehensive testing:

  • Unit Tests: Fast, isolated tests for individual components
  • End-to-End Tests: Integration tests against real Substack servers
# Run unit tests
npm test

# Run E2E tests (requires API credentials)
npm run test:e2e

# Run all tests
npm run test:all

For E2E tests, copy .env.example to .env and add your Substack API credentials.

License

MIT