How to Get a Medium Article Information

Using JavaScript and Medium API

Medium is one of the most popular platforms for sharing articles and ideas, ranging from technical content to personal stories.

For developers and data enthusiasts, fetching detailed information about a Medium article can be incredibly useful for analytics, content curation, or simply learning more about the article’s metadata.

This guide explains how to retrieve detailed information about a Medium article such as its title, author, publication date, tags, claps, and more using the medium-api-js package.

Prerequisites

Before you start, make sure you have the following:

Code Walkthrough

1. Importing Required Libraries

The code begins by importing the necessary libraries. The medium-api-js package is used to interact with the Medium API, and dotenv is used to manage environment variables securely.

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

dotenv.config();

2. Initializing the Medium Client

Next, initialize the Medium client using your RapidAPI key:

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

Here, the API key is retrieved from the .env file, ensuring security and ease of configuration.

3. Specifying the Article ID

You need to know the article ID for which you want to fetch information. The ID is typically part of the article’s URL.

const articleId = '67fa62fc1971';

For instance, if the article URL is:

https://medium.com/some-publication/why-its-super-hard-to-be-an-ml-researcher-or-developer-67fa62fc1971

The article ID is 67fa62fc1971.

4. Fetching Article Information

Call the getArticleInfo method with the article ID to fetch detailed information:

medium.getArticleInfo(articleId).then(data => {
    console.log('Article Info:', data);
});

Running the Code

To execute the code, run the following command in your terminal:

node getArticleInfo.js

Ensure that your .env file is configured correctly and that you have a valid article ID.

Output Explanation

When you run the script, you’ll get a detailed response containing various metadata about the article. Here’s an example of the output:

Key Output Fields

Potential Use Cases

Summary

Fetching Medium article information is a powerful way to gain insights into the platform’s content.

Whether you’re a developer building analytical tools, a writer analyzing your own work, or a content curator, this guide equips you to interact with Medium’s API effectively.

If you have any questions about the Medium API or this implementation, feel free to reach out to nishu@mediumapi.com.

nishu@mediumapi.com