How to Get Article Assets Using Medium API

(Using JavaScript)

By leveraging the Medium API, you can automate the task of gathering all assets from a Medium article—such as images, embeds, and links. This guide walks you through the process step-by-step, ensuring you can extract and utilize article assets effortlessly.

Prerequisites

Ensure you have the following:

Install the required packages by running:

npm install medium-api-js dotenv

Code Explanation

Step 1: Import Required Modules

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

This step imports the necessary modules to interact with the Medium API and handle environment variables securely.

Step 2: Configure Environment Variables

dotenv.config();

The dotenv.config() method reads the .env file, loading the API key into process.env, keeping it secure and accessible.

Create a .env file with the following content:

RAPIDAPI_KEY=your_actual_api_key

Step 3: Initialize the Medium API Instance

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

An instance of the Medium API is initialized using the provided API key, enabling interaction with Medium's API methods.

Step 4: Specify the Article ID

const articleId = '67fa62fc1971';

Replace the placeholder ID with the actual article ID. This ID is typically found in the Medium article's URL.

Step 5: Fetch Article Assets

medium.getArticleAssets(articleId).then(data => console.log('Article Assets:', data));

This step fetches all the assets of the specified article using the getArticleAssets method. The retrieved data is logged to the console and includes:

Command to Run the Code

Save the script as getArticleAssets.js and run it using:

node getArticleAssets.js

Output and Explanation

The output is a JSON object containing all assets of the specified article:

Potential Use Cases

Summary

This guide demonstrates how to fetch assets from a Medium article using medium-api-js. By leveraging this functionality, you can streamline tasks like content analysis, SEO audits, and asset management.

For questions, feel free to contact me at nishu@mediumapi.com.

Happy coding!

nishu@mediumapi.com