How to Get Articles from a Medium List

(Using Javascript)

Fetching articles from specific lists on Medium can help developers and content creators organize data for analytics, create curated collections, or power content-based applications.

In this article, you'll learn how to fetch all articles from a given Medium list ID using the medium-api-js package, logging the details to the console.

Prerequisites

Before running the code, ensure you meet the following requirements:

Code Explanation

1. Import Required Modules

The following modules are imported:

import Medium from 'medium-api-js';
import dotenv from 'dotenv';

2. Load Environment Variables

dotenv.config();

The dotenv.config() method loads the .env file into process.env, making your API key accessible during runtime.

3. Initialize the Medium API Instance

const medium = new Medium(process.env.RAPIDAPI_KEY);

An instance of the Medium class is created, with the API key passed from process.env.RAPIDAPI_KEY.

4. Fetch and Log Articles from a Specific List

medium.getListArticles('3d8f744f5370').then(data => {
    console.log('List Articles:', data);
});

getListArticles('3d8f744f5370'): Fetches all articles belonging to the list with ID 3d8f744f5370.

.then(data => {...}: Handles the resolved promise, where the list data is logged to the console.

Command to Run the Code

Save the script as getListArticles.js and execute it using Node.js:

node getListArticles.js

Output Explanation

Upon running the script, the following output is logged:

Key Components:

Potential Use Cases

Summary

This code provides a straightforward way to fetch articles from a Medium list using medium-api-js. It is highly extensible and can be adapted for various use cases, from analytics to custom applications.

For any questions or help with the Medium API, feel free to contact me at nishu@mediumapi.com.

Happy coding!

nishu@mediumapi.com