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.
Ensure you have the following:
medium-api-js: A JavaScript wrapper for interacting with the Medium API.dotenv: To manage environment variables securely.Install the required packages by running:
npm install medium-api-js dotenvimport 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.
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_keyconst 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.
const articleId = '67fa62fc1971';Replace the placeholder ID with the actual article ID. This ID is typically found in the Medium article's URL.
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:
Save the script as getArticleAssets.js and run it using:
node getArticleAssets.jsThe output is a JSON object containing all assets of the specified article:
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!