How to Get Medium Publication Newsletter Information

(Using Medium API Python Package)

This guide will walk you through fetching newsletter-related information for a specific Medium publication using the Medium API. By the end of this article, you'll understand how to retrieve details such as the newsletter ID, name, description, slug, number of subscribers, and image URL.

Prerequisites

Before we start, make sure you have the `medium-api` Python package installed. You can install it using pip:

install medium-api

Step-by-Step Guide

1. Import Required Libraries

First, you need to import the necessary libraries for interacting with the Medium API and handling environment variables. Here’s how you do it:

2. Get API Key from Environment

To authenticate with the Medium API, you need an API key. This key should be stored in an environment variable called `RAPIDAPI_KEY`. Retrieve this key using the `os.getenv()` function:

3. Create a Medium Object

With the API key in hand, create an instance of the `Medium` class. This object will allow you to interact with the Medium API:

4. Create a Publication Object

You’ll need the ID of the publication you want to fetch information from. Replace `"98111c9905da"` with the actual ID of the publication. Then, create a `Publication` object:

5. Fetch and Print Newsletter Information

Finally, retrieve and print the newsletter information associated with the publication. The `save_info()` method updates the newsletter details, and you can then access various attributes:

Summary

This guide provided a step-by-step approach to fetching newsletter information from a Medium publication using the Medium API. By following these instructions, you can easily retrieve details such as the newsletter's ID, name, description, slug, subscriber count, and image URL.

Output