Hey there, fellow developer! Ready to supercharge your PHP project with the power of Fireflies.ai? You're in the right place. Fireflies.ai is a game-changer when it comes to meeting transcription and analysis, and their API is the secret sauce that'll let you tap into all that goodness. In this guide, we'll walk through building a solid integration that'll have you manipulating meeting data like a pro.
Before we dive in, make sure you've got:
Got those? Great! Let's get cooking.
First things first, let's get our project structure in order:
composer require guzzlehttp/guzzle
Fireflies.ai uses API key authentication. Let's set that up:
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; $client = new Client([ 'base_uri' => 'https://api.fireflies.ai/graphql', 'headers' => [ 'Authorization' => 'Bearer YOUR_API_KEY_HERE', 'Content-Type' => 'application/json', ], ]);
Replace YOUR_API_KEY_HERE
with your actual API key, and you're good to go!
Let's start with a simple request to get user information:
$query = <<<'GRAPHQL' query { me { id email } } GRAPHQL; $response = $client->post('', [ 'json' => ['query' => $query] ]); $data = json_decode($response->getBody(), true); print_r($data['data']['me']);
Run this, and you should see your user info. Cool, right?
Now, let's fetch a list of transcripts:
$query = <<<'GRAPHQL' query { transcripts(first: 10) { edges { node { id title date } } } } GRAPHQL; $response = $client->post('', [ 'json' => ['query' => $query] ]); $data = json_decode($response->getBody(), true); foreach ($data['data']['transcripts']['edges'] as $edge) { print_r($edge['node']); }
This will give you the first 10 transcripts. Play around with the first
parameter to get more or fewer.
Creating a new meeting is just as easy:
$mutation = <<<'GRAPHQL' mutation { createMeeting(input: { title: "API Test Meeting" date: "2023-06-15T14:00:00Z" }) { meeting { id title } } } GRAPHQL; $response = $client->post('', [ 'json' => ['query' => $mutation] ]); $data = json_decode($response->getBody(), true); print_r($data['data']['createMeeting']['meeting']);
Webhooks are a great way to get real-time updates. Here's a simple webhook handler:
<?php $payload = file_get_contents('php://input'); $event = json_decode($payload, true); if ($event['type'] === 'transcript.completed') { // Handle new transcript $transcriptId = $event['data']['transcript']['id']; // Do something with the new transcript }
Remember to set up your webhook URL in the Fireflies.ai dashboard!
Always wrap your API calls in try-catch blocks:
try { $response = $client->post('', [ 'json' => ['query' => $query] ]); // Handle response } catch (\GuzzleHttp\Exception\GuzzleException $e) { // Handle error echo "An error occurred: " . $e->getMessage(); }
And don't forget about rate limiting! Be a good API citizen and respect the limits.
Unit testing is your friend. Here's a quick example using PHPUnit:
use PHPUnit\Framework\TestCase; class FirefliesApiTest extends TestCase { public function testGetUserInfo() { // Your test code here } }
And there you have it! You've just built a solid Fireflies.ai API integration in PHP. From here, the sky's the limit. You could build a custom dashboard, automate meeting summaries, or even create a chatbot that answers questions based on meeting transcripts.
Remember, the best way to learn is by doing. So go ahead, experiment, break things, and build something awesome!
Now go forth and code, you magnificent developer, you!