In the vast world of Medium, finding curated lists that align with your interests can enhance your reading and exploration experience.
This guide demonstrates how to use the Medium API to search for lists based on a specific query. As a practical example, we'll look at searching for "productivity" lists. By the end, you'll understand how the code works, how to run it, and how you can use it for various purposes.
Before diving into the implementation, ensure you have the following:
.env
file to securely store your API key.medium-api-js
Package: Install this Medium API wrapper by running:npm install medium-api-js
dotenv
Package: Install dotenv to manage environment variables by running:npm install dotenv
import Medium from 'medium-api-js';
import dotenv from 'dotenv';
Medium
: This is the Medium API wrapper that simplifies API interactions.dotenv
: This package loads environment variables from a .env
file, helping you keep sensitive data secure.dotenv.config();
dotenv.config()
: Initializes dotenv, allowing the API key stored in the .env
file to be accessible in the script.const medium = new Medium(process.env.RAPIDAPI_KEY);
process.env.RAPIDAPI_KEY
: Retrieves the API key from the environment variables.new Medium()
: Creates an instance of the Medium API client, enabling API calls.medium.getSearchLists('productivity').then(data => {
console.log('Search Results for Lists:', data);
});
getSearchLists('productivity')
: Invokes the API to search for lists related to the query 'productivity'
.then(data => { ... })
: Processes the API response and logs the results to the console.To execute this script:
getSearchLists.js
..env
file contains the following line:RAPIDAPI_KEY=your_api_key_here
node getSearchLists.js
When the script runs, you'll see output similar to this:
lists
: Contains an array of list IDs that match the search query.search_query
: Tells the query used for the search ("productivity"
in this case).Searching for lists on Medium is a powerful way to uncover curated content tailored to your interests. This guide provided a detailed walkthrough of the process, from setting up your environment to running the code and interpreting its output.
For further questions or assistance, feel free to reach out at nishu@mediumapi.com. Enjoy exploring Medium's rich content ecosystem!