Fetching root tags from Medium can help developers, content creators, or businesses organize and categorize content effectively. Tags like "technology," "self-improvement," or "culture" act as thematic identifiers that make articles more discoverable on Medium.
This guide explains how to programmatically retrieve these root tags using the medium-api-js
package, a wrapper for the Medium API.
Before getting started, ensure you have the following:
dotenv
Library: Install the dotenv library to securely store and access environment variables.To install the necessary packages, use the following commands:
npm install medium-api-js dotenv
import Medium from 'medium-api-js';
import dotenv from 'dotenv';
dotenv.config();
Medium
: This is the Medium API wrapper that provides a simple interface for making requests to the Medium platform.dotenv
: This library allows you to securely store API keys and other sensitive configuration details in a .env
file. By calling dotenv.config()
, you load the configuration variables into process.env
.const medium = new Medium(process.env.RAPIDAPI_KEY);
process.env.RAPIDAPI_KEY
: Retrieves your API key stored in the .env
file. This API key is essential for authenticating requests to Medium’s API.medium.getRootTags()
.then(data => {
console.log('Root Tags:', data);
});
getRootTags()
: This method fetches the top-level tags available on the Medium platform. These root tags represent major content categories..then(data => { ... })
: Handles the promise returned by getRootTags()
and logs the result to the console.To execute the script, save it as getRootTags.js
and run the following command in your terminal:
node getRootTags.js
When the code runs successfully, it fetches the root tags from Medium and logs them to the console. For example:
root_tags
: An array containing the top-level categories available on Medium.count
: The total number of root tags retrieved.By fetching root tags from Medium, you can gain valuable insights into the platform’s organizational structure and enhance your application’s capabilities.
This guide covered how to use the medium-api-js
package to retrieve and utilize these tags effectively. If you have any questions or need further assistance, feel free to reach out at nishu@mediumapi.com.