Hey there, fellow developer! Ready to dive into the world of Bloomerang API integration? You're in for a treat. We'll be using the nifty phospr/bloomerang package to make our lives easier. Let's get cracking!
Before we jump in, make sure you've got:
First things first, let's get that package installed:
composer require phospr/bloomerang
Easy peasy, right?
Now, let's set up those API credentials and get our Bloomerang client ready to roll:
use Phospr\Bloomerang\Client; $apiKey = 'your_api_key_here'; $client = new Client($apiKey);
Let's make our first API request. How about fetching a constituent?
$constituent = $client->constituents->get(123456); echo $constituent->firstName . ' ' . $constituent->lastName;
Boom! You're now officially talking to Bloomerang.
$constituents = $client->constituents->list(['limit' => 10]);
$newConstituent = $client->constituents->create([ 'firstName' => 'John', 'lastName' => 'Doe', 'email' => '[email protected]' ]);
$transaction = $client->transactions->create([ 'constituentId' => 123456, 'amount' => 100.00, 'date' => '2023-05-01' ]);
$interaction = $client->interactions->create([ 'constituentId' => 123456, 'channel' => 'EMAIL', 'subject' => 'Follow-up call' ]);
Don't let those pesky errors catch you off guard:
try { $constituent = $client->constituents->get(999999); } catch (\Exception $e) { echo "Oops! " . $e->getMessage(); }
$page = 1; do { $constituents = $client->constituents->list(['page' => $page, 'limit' => 100]); // Process constituents $page++; } while (count($constituents) > 0);
$recentDonors = $client->constituents->list([ 'lastTransactionDate' => ['gte' => '2023-01-01'], 'sort' => '-lastTransactionDate' ]);
Don't forget to test your integration! Use PHPUnit and mock those API responses:
use PHPUnit\Framework\TestCase; use Phospr\Bloomerang\Client; class BloomerangTest extends TestCase { public function testGetConstituent() { $mock = $this->createMock(Client::class); $mock->method('get')->willReturn(['id' => 123, 'firstName' => 'John']); // Assert your expectations here } }
And there you have it! You're now armed and dangerous with Bloomerang API integration skills. Remember, the API documentation is your best friend, so keep it bookmarked. Happy coding, and may your integrations be ever smooth and error-free!