Medium publications often feature newsletters that help reach a broader audience with curated content, insights, and updates. Knowing how to fetch newsletter details for a publication can be useful for developers creating reporting tools, analytics dashboards, or simply exploring publication data.
This article explains how to retrieve Medium publication newsletter information using the Medium API JS package.
By the end of this guide, you will understand how to fetch and interpret a publication’s newsletter details, including its name, description, creator ID, and more.
To get started, ensure the following prerequisites are met:
medium-api-js
and dotenv
packages. Install them by running:npm install medium-api-js dotenv
.env
file in your project directory and add your RapidAPI key:RAPIDAPI_KEY=your-rapidapi-key-here
import Medium from 'medium-api-js';
import dotenv from 'dotenv';
dotenv.config();
medium-api-js
: This is the Medium API wrapper that simplifies API interactions.dotenv
: Used to load environment variables from the .env
file.dotenv.config()
: Ensures the environment variables are loaded into the application.const medium = new Medium(process.env.RAPIDAPI_KEY);
process.env.RAPIDAPI_KEY
: Retrieves the API key from the .env
file.new Medium()
: Creates an instance of the Medium API client using the provided API key.const publicationId = '98111c9905da';
publicationId
is a unique identifier for the Medium publication. Replace this with the ID of the publication you’re querying.medium.getPublicationNewsletter(publicationId)
.then(data => {
console.log('Publication Newsletter:', data);
});
medium.getPublicationNewsletter(publicationId)
: Sends a request to fetch newsletter details for the specified publication..then(data => {...})
: Handles the resolved promise and logs the returned data to the console.Save the code in a file named getPublicationNewsletter.js
. Open your terminal and run:
node getPublicationNewsletter.js
The output displays detailed information about the publication’s newsletter. For example:
You can fetch Medium publication newsletter details using the Medium API JS package. This data can be leveraged for a variety of applications, from analytics to marketing.
By following the steps outlined above, you can quickly access and utilize valuable newsletter information.
If you have any questions about the Medium API or need further assistance, feel free to reach out at nishu@mediumapi.com.