Hey there, fellow JavaScript devs! Ready to supercharge your app with some sweet transcription capabilities? Let's dive into integrating the Fireflies.ai API for a user-facing experience that'll knock your socks off.
First things first, you'll need to grab those API credentials. Head over to the Fireflies.ai developer portal and snag your API key. If you're dealing with user-specific data, you might need to implement OAuth 2.0. Here's a quick example of how to set up your API calls:
const axios = require('axios'); const firefliesApi = axios.create({ baseURL: 'https://api.fireflies.ai/graphql', headers: { 'Authorization': 'Bearer YOUR_API_KEY_HERE', 'Content-Type': 'application/json' } });
Now that we're all set up, let's grab some transcripts. Here's how you can fetch a user's transcripts:
async function getTranscripts() { const query = ` query { transcripts { id title created_at } } `; try { const response = await firefliesApi.post('', { query }); return response.data.data.transcripts; } catch (error) { console.error('Error fetching transcripts:', error); } }
Want details on a specific transcript? No sweat:
async function getTranscriptDetails(id) { const query = ` query { transcript(id: "${id}") { id title text speakers { name email } } } `; try { const response = await firefliesApi.post('', { query }); return response.data.data.transcript; } catch (error) { console.error('Error fetching transcript details:', error); } }
Creating a new transcript? Coming right up:
async function createTranscript(title, audioUrl) { const mutation = ` mutation { createTranscript(input: { title: "${title}", audio_url: "${audioUrl}" }) { id title } } `; try { const response = await firefliesApi.post('', { query: mutation }); return response.data.data.createTranscript; } catch (error) { console.error('Error creating transcript:', error); } }
Need to update an existing transcript? We've got you covered:
async function updateTranscript(id, newTitle) { const mutation = ` mutation { updateTranscript(id: "${id}", input: { title: "${newTitle}" }) { id title } } `; try { const response = await firefliesApi.post('', { query: mutation }); return response.data.data.updateTranscript; } catch (error) { console.error('Error updating transcript:', error); } }
To keep your data fresh, set up a webhook listener. Here's a quick Express.js example:
const express = require('express'); const app = express(); app.post('/webhook', express.json(), (req, res) => { const { event, data } = req.body; switch (event) { case 'transcript.created': console.log('New transcript created:', data.id); // Handle new transcript break; case 'transcript.updated': console.log('Transcript updated:', data.id); // Handle updated transcript break; // Add more cases as needed } res.sendStatus(200); }); app.listen(3000, () => console.log('Webhook listener running on port 3000'));
Always check for errors and respect those rate limits, folks:
async function makeApiCall() { try { const response = await firefliesApi.post('', { query: 'YOUR_QUERY_HERE' }); const rateLimitRemaining = response.headers['x-ratelimit-remaining']; if (rateLimitRemaining < 10) { console.warn('Approaching rate limit, slow down!'); } return response.data; } catch (error) { if (error.response && error.response.status === 429) { console.error('Rate limit exceeded. Try again later.'); } else { console.error('API error:', error.message); } } }
And there you have it! You're now equipped to read, write, and sync data like a Fireflies.ai API ninja. Remember, with great power comes great responsibility – use these skills wisely and build something awesome!
Got questions? Feeling stuck? Don't sweat it – the Fireflies.ai docs are your best friend. Now go forth and code, you magnificent developer, you!