How to Get a Medium Publication ID

Using Medium API JS Package

If you’re working with the Medium API to integrate Medium publications into your application, one of the key identifiers you’ll need is the publication ID. This unique identifier is essential for performing operations like fetching articles or analyzing publication data.

Let’s walk through how to fetch the publication ID for a given publication slug using the medium-api-js package.

Prerequisites

Before proceeding, ensure the following:

Code Breakdown

This script fetches the publication ID for a given Medium publication slug. Let’s break it down:

1. Importing Required Modules

import Medium from 'medium-api-js';
import dotenv from 'dotenv';

dotenv.config();

2. Initializing the Medium API Client

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

3. Defining the Publication Slug

const publicationSlug = 'codex';

4. Fetching the Publication ID

medium.getPublicationId(publicationSlug).then(data => {
    console.log('Publication ID:', data);
});

Running the Script

Save the script to a file (e.g., getPublicationId.js) and run it using Node.js:

node getPublicationId.js

Output Explanation

When the script runs successfully, you’ll see an output similar to this:

Potential Use Cases

Summary

In this tutorial, you learned how to fetch a Medium publication ID using the medium-api-js package. This process enables seamless integration with Medium publications, allowing for enhanced functionalities like article retrieval and content analysis.

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

nishu@mediumapi.com