How to Get Medium Publications Where You Are a Writer or Editor

Using Javascript

Medium is a popular platform for sharing ideas and stories, and being a writer or editor in a publication can significantly enhance your reach.

In this guide, you’ll learn how to retrieve a list of Medium publications where a user is either a writer or an editor. This can be helpful for gaining insights and providing analystics on a user's engagement with different publications.

Prerequisites

To follow this guide, ensure you have the following:

npm install medium-api-js dotenv

Step-by-Step Code Explanation

1. Import Required Packages

import Medium from 'medium-api-js';
import dotenv from 'dotenv';
dotenv.config();

Here:

2. Initialize the Medium API Client

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

The Medium object is initialized with the API key retrieved from the .env file. This key authenticates your requests to the Medium API.

3. Define the User ID

const userId = '14d5c41e0264';

This is the Medium user ID for the account whose publications you want to retrieve. Replace this with the desired user’s ID.

4. Fetch Publications

medium.userPublications(userId)
    .then(data => console.log('User Publications:', data));

Here:

Running the Code

Save the code in a file, e.g., getUserPublications.js. To run it, use the command:

node getUserPublications.js

Output and Explanation

When the code executes, it outputs the user’s publications, including their IDs and roles:

You can use these IDs to fetch more details about each publication or build tools to manage them.

Potential Use Cases

Summary

Fetching publications where a user is a writer or editor is straightforward using the medium-api-js package. With this information, you can gain more insights on a user's preferences and engagement with publications.

If you have any questions or need further assistance, feel free to reach out at nishu@mediumapi.com.

Happy coding!

nishu@mediumapi.com