API recipe

Search and Filter Podcasts

Search podcast titles and descriptions, apply filters, and retrieve multiple pages of results.

intermediate 15 minutes PodEngine Team
SearchPodcastsFilteringPagination

Before you start

  • API token
  • A topic you want to search for

Choose your example

Your selection applies to every step. HTTP uses built-in clients without the Pod Engine libraries.

Use Node.js 22 or newer. Save the complete script as recipe.mjs.

npm install @podengine/sdk
# macOS / Linux shell; set the same variable in your shell on Windows
export PODENGINE_API_KEY="YOUR_API_KEY"
node recipe.mjs

Set up the client

Start your file with this setup, then append each step in order. The complete script below includes everything.

import { PodEngine } from '@podengine/sdk';

const apiKey = process.env.PODENGINE_API_KEY;
if (!apiKey) throw new Error('Set PODENGINE_API_KEY before running this recipe');
const pe = new PodEngine({
  apiKey,
  baseUrl: process.env.PODENGINE_API_URL || 'https://api.podengine.ai',
});
Complete runnable script
Download script
import { PodEngine } from '@podengine/sdk';

const apiKey = process.env.PODENGINE_API_KEY;
if (!apiKey) throw new Error('Set PODENGINE_API_KEY before running this recipe');
const pe = new PodEngine({
  apiKey,
  baseUrl: process.env.PODENGINE_API_URL || 'https://api.podengine.ai',
});

const searchTerms = [
  {
    searchTerm: 'technology',
    searchType: 'text',
    searchTargets: ['podcast-title', 'podcast-description'],
    searchTermOptions: { matchMode: 'must' },
  },
];
const query = { searchTerms, pageSize: 20 };
const firstPage = await pe.search.searchPodcasts(query);
console.log(`Found ${firstPage.result.hits.length} podcasts on this page`);

const filteredQuery = {
  ...query,
  languages: ['en'],
  includeItunesGenres: ['Technology'],
  minTotalEpisodes: 10,
};
const filteredPage = await pe.search.searchPodcasts(filteredQuery);
console.log(filteredPage.result.hits);

const maxResults = 100;
const podcasts = [];
let cursor = null;
do {
  const page = await pe.search.searchPodcasts({ ...filteredQuery, cursor });
  podcasts.push(...page.result.hits.slice(0, maxResults - podcasts.length));
  const nextCursor = page.cursor;
  if (!page.result.hits.length || !nextCursor || nextCursor === cursor) break;
  cursor = nextCursor;
} while (podcasts.length < maxResults);
console.log(`Retrieved ${podcasts.length} podcasts`);
1

Basic Podcast Search

Create a text search over podcast titles and descriptions. The must match mode requires the term to match. HTTP requests send a JSON body to POST /api/v1/search/podcasts. The SDK unwraps the HTTP response’s data envelope; the returned podcasts are in result.hits.

const searchTerms = [
  {
    searchTerm: 'technology',
    searchType: 'text',
    searchTargets: ['podcast-title', 'podcast-description'],
    searchTermOptions: { matchMode: 'must' },
  },
];
const query = { searchTerms, pageSize: 20 };
const firstPage = await pe.search.searchPodcasts(query);
console.log(`Found ${firstPage.result.hits.length} podcasts on this page`);
2

Advanced Filtering

Narrow the same search to English-language podcasts in the Technology genre with at least ten episodes. Filters combine with the search terms. Python SDK keyword arguments use snake_case, while HTTP JSON fields and nested search-term dictionaries use the API’s camelCase names.

const filteredQuery = {
  ...query,
  languages: ['en'],
  includeItunesGenres: ['Technology'],
  minTotalEpisodes: 10,
};
const filteredPage = await pe.search.searchPodcasts(filteredQuery);
console.log(filteredPage.result.hits);
3

Pagination and Bulk Retrieval

Keep the search and filters unchanged and pass each response’s cursor into the next request. Stop when there are no hits, no new cursor, or the local maximum is reached. This example starts a fresh traversal and collects at most 100 results.

const maxResults = 100;
const podcasts = [];
let cursor = null;
do {
  const page = await pe.search.searchPodcasts({ ...filteredQuery, cursor });
  podcasts.push(...page.result.hits.slice(0, maxResults - podcasts.length));
  const nextCursor = page.cursor;
  if (!page.result.hits.length || !nextCursor || nextCursor === cursor) break;
  cursor = nextCursor;
} while (podcasts.length < maxResults);
console.log(`Retrieved ${podcasts.length} podcasts`);