A Node.js wrapper for the Supadata API v1, designed for fetching web content and generating YouTube video transcripts.
supdata.ai is a Web & YouTube to text API for makers
- Simple API client for all Supadata endpoints
- Promise-based interface with proper error handling
- TypeScript-friendly JSDoc comments
- Examples for common use cases
# Clone the repository
git clone https://github.com/servatj/supadata-api-client.git
# Navigate to the directory
cd supadata-api-client
# Install dependencies
npm install
# Copy and edit the environment variables
cp .env.example .env
# Edit the .env file with your API key
Or if you're using it as a package:
npm install supadata-api-client
Create a .env
file in the root directory with your Supadata API key:
SUPADATA_API_KEY=your_api_key_here
const SupadataClient = require('supadata-api-wrapper');
// Initialize the client with your API key
const client = new SupadataClient('your_api_key_here');
// Or load from environment variables
// const client = new SupadataClient(process.env.SUPADATA_API_KEY);
// Example: Get a YouTube video transcript
async function getTranscript() {
try {
const transcript = await client.getTranscript('dQw4w9WgXcQ');
console.log(transcript);
} catch (error) {
console.error('Error:', error.message);
}
}
getTranscript();
const client = new SupadataClient(apiKey, options);
Parameters:
apiKey
(string, required): Your Supadata API keyoptions
(object, optional):baseUrl
(string, optional): Custom API base URL (default: 'https://api.supadata.ai')
// Get transcript for a YouTube video
const transcript = await client.getTranscript('videoId');
// Translate a YouTube video transcript
const translatedTranscript = await client.translateTranscript('videoId', 'targetLanguage');
// Get content from a URL
const content = await client.getUrlContent('https://example.com', options);
// Map a website structure
const siteMap = await client.mapWebsite('https://example.com', options);
// Start a website crawl
const crawlJob = await client.crawlWebsite('https://example.com', options);
// Get crawl results
const crawlResults = await client.getCrawlResult('jobId');
// Get YouTube video data
const video = await client.getVideo('videoId');
// Get YouTube channel data
const channel = await client.getChannel('channelId');
// Get YouTube playlist data
const playlist = await client.getPlaylist('playlistId');
// Get videos from a channel
const channelVideos = await client.getChannelVideos('channelId', options);
// Get videos from a playlist
const playlistVideos = await client.getPlaylistVideos('playlistId', options);
// Check if your API key is valid
const status = await client.checkApiKey();
The client includes enhanced error handling that provides meaningful error messages:
try {
const transcript = await client.getTranscript('invalid_video_id');
} catch (error) {
console.error(error.message); // Formatted error message
console.error(error.status); // HTTP status code if available
console.error(error.data); // Error response data if available
}
Check the examples
directory for more usage examples:
# Run the basic usage example
node examples/basic-usage.js transcript dQw4w9Wg
This package includes comprehensive unit tests using Jest. To run the tests:
npm test
This will run all tests and generate a coverage report in the coverage
directory.
</rewritten_file>