Back

Step by Step Guide to Building a Streak API Integration in PHP

Aug 14, 20246 minute read

Introduction

Hey there, fellow developer! Ready to supercharge your CRM game with Streak? Let's dive into building a robust Streak API integration using PHP. We'll be leveraging the awesome xotelia/streak-php-client package to make our lives easier. Buckle up!

Prerequisites

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

  • A PHP environment (you're a pro, so I'm sure you've got this covered)
  • Composer installed (because who doesn't love dependency management?)
  • Streak API credentials (grab 'em from your Streak account)

Installation

First things first, let's get that xotelia/streak-php-client package installed. Fire up your terminal and run:

composer require xotelia/streak-php-client

Easy peasy, right?

Setting up the Streak Client

Now, let's initialize our Streak client. It's as simple as:

use Streak\Client; $client = new Client('your_api_key_here');

Boom! You're ready to roll.

Basic Operations

Creating a Pipeline

Let's start by creating a pipeline:

$pipeline = $client->pipelines()->create([ 'name' => 'My Awesome Pipeline' ]);

Adding a Box (Deal) to a Pipeline

Now, let's add a box to our shiny new pipeline:

$box = $client->boxes()->create([ 'name' => 'Potential Big Client', 'pipelineKey' => $pipeline['key'] ]);

Updating Box Fields

Updating fields is a breeze:

$client->boxes()->update($box['key'], [ 'fields' => [ 'dealSize' => 1000000, 'stage' => 'Negotiation' ] ]);

Advanced Operations

Searching for Boxes

Need to find specific boxes? No sweat:

$results = $client->boxes()->search([ 'pipelineKey' => $pipeline['key'], 'query' => 'Big Client' ]);

Working with Tasks

Tasks are crucial. Here's how to add one:

$task = $client->tasks()->create([ 'boxKey' => $box['key'], 'text' => 'Follow up with client', 'dueDate' => strtotime('+1 week') ]);

Managing Team Members

Got a growing team? Add them to your Streak workspace:

$member = $client->teamMembers()->create([ 'email' => '[email protected]' ]);

Error Handling

Always be prepared! Here's how to handle common issues:

try { // Your Streak API calls here } catch (\Streak\Exception\RateLimitException $e) { // Handle rate limiting sleep(60); // Wait a bit and retry } catch (\Streak\Exception\NotFoundException $e) { // Handle not found errors } catch (\Streak\Exception\ApiException $e) { // Handle other API errors }

Best Practices

  1. Cache, cache, cache! Store frequently accessed data locally to reduce API calls.
  2. Batch operations when possible to minimize requests.
  3. Use webhooks for real-time updates instead of constant polling.

Example Use Case: Simple CRM Integration

Let's tie it all together with a quick example:

function createLead($name, $email, $dealSize) { global $client; $pipeline = $client->pipelines()->getByName('Sales Pipeline'); $box = $client->boxes()->create([ 'name' => $name, 'pipelineKey' => $pipeline['key'], 'fields' => [ 'email' => $email, 'dealSize' => $dealSize ] ]); $client->tasks()->create([ 'boxKey' => $box['key'], 'text' => "Follow up with $name", 'dueDate' => strtotime('+3 days') ]); return $box; } $newLead = createLead('Jane Doe', '[email protected]', 50000); echo "New lead created: " . $newLead['key'];

Conclusion

And there you have it! You're now armed with the knowledge to build a killer Streak API integration. Remember, the key to mastering any API is practice and exploration. Don't be afraid to dive into the Streak API docs for more advanced features.

Now go forth and build something awesome! 🚀