Back

Step by Step Guide to Building a Fireflies.ai API Integration in PHP

Aug 14, 20247 minute read

Introduction

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.

Prerequisites

Before we dive in, make sure you've got:

  • A PHP environment up and running (PHP 7.4+ recommended)
  • A Fireflies.ai API key (if you don't have one, hop over to their developer portal and snag one)

Got those? Great! Let's get cooking.

Setting up the project

First things first, let's get our project structure in order:

  1. Create a new directory for your project
  2. Initialize Composer (you're using Composer, right?)
  3. Install Guzzle for making HTTP requests:
composer require guzzlehttp/guzzle

Authentication

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!

Basic API Requests

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?

Working with Transcripts

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.

Managing Meetings

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']);

Advanced Features

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!

Error Handling and Best Practices

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.

Testing the Integration

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 } }

Conclusion

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!

Resources

Now go forth and code, you magnificent developer, you!