Fetching responses or comments on a specific Medium list can be extremely valuable for content creators, developers, or marketers looking to analyze engagement and feedback.
Whether you’re building analytics tools or simply want to monitor user interaction on a Medium list, this guide shows you how to achieve this using the medium-api-js
package.
By the end, you’ll know how to fetch comments from any Medium list programmatically.
Before diving into the implementation, ensure you have the following:
medium-api-js
package for accessing the Medium API.dotenv
for loading environment variables securely.You can install the necessary dependencies using the following commands:
npm install medium-api-js dotenv
This script fetches responses to a Medium list by its ID. Let’s break it down step-by-step:
import Medium from 'medium-api-js';
import dotenv from 'dotenv';
dotenv.config();
import Medium
: The medium-api-js
package is used to interact with Medium’s API.import dotenv
: The dotenv
package loads environment variables from a .env
file.dotenv.coig()
: This initializes dotenv
, making the environment variables accessible in your code.const medium = new Medium(process.env.RAPIDAPI_KEY);
process.env.RAPIDAPI_KEY
: Fetches your API key securely from the environment variables.new Medium()
: Creates an instance of the Medium API client using the API key.medium.getListResponses('3d8f744f5370').then(data => {
console.log('List Responses:', data);
});
getListResponses('3d8f744f5370')
: Fetches responses (comments) for the Medium list with the specified ID (‘3d8f744f5370’)..then(data => { ... })
: Handles the API response asynchronously. The data
parameter contains the list responses.console.log()
: Outputs the fetched responses to the console.Save the code to a file named getListResponses.js
and execute it using the following command in your terminal:
node getListResponses.js
Ensure that your .env
file contains your API key in the following format:
RAPIDAPI_KEY=your_medium_api_key_here
When you run the script, the output will look like this:
id
: Confirms the ID of the queried Medium list.responses
: Contains an array of responses (comments) on the list. In this case, it’s empty (‘[]’), indicating no comments.count
: Indicates the total number of responses. Here, it’s 0
, meaning there are no comments on this list.This guide walked you through the setup, implementation, and potential applications of using Medium API JS package to get responses on a Medium list.
If you have any questions about Medium API or this code, feel free to reach out at nishu@mediumapi.com.
Start leveraging Medium’s data today to understand your audience better!