Installation Add the bundle via Composer:
composer require cekurte/insightlybundle
Enable the bundle in config/bundles.php:
Cekurte\InsightlyBundle\CekurteInsightBundle::class => ['all' => true],
Configuration Publish the default config:
php bin/console insightly:install
Update config/packages/cekurte_insightly.yaml with your Insightly API credentials:
cekurte_insightly:
api_key: 'your_api_key_here'
api_secret: 'your_api_secret_here'
base_url: 'https://api.insightly.com/v3.1'
First Use Case Fetch a contact by ID:
use Cekurte\InsightlyBundle\Service\InsightlyService;
class SomeController extends AbstractController
{
public function showContact(InsightlyService $insightly)
{
$contact = $insightly->getContact(12345);
return $this->render('contact/show.html.twig', ['contact' => $contact]);
}
}
CRUD Operations Use the service methods for standard operations:
// Create
$contact = $insightly->createContact(['firstName' => 'John', 'lastName' => 'Doe']);
// Read
$contact = $insightly->getContact($id);
// Update
$insightly->updateContact($id, ['email' => 'john@example.com']);
// Delete
$insightly->deleteContact($id);
Querying with Filters Fetch contacts with custom filters:
$contacts = $insightly->getContacts([
'filter' => [
'firstName' => 'John',
'email' => 'john@example.com'
]
]);
Relationships Link entities (e.g., contacts to organizations):
$insightly->linkContactToOrganization($contactId, $orgId);
Webhooks Configure webhook subscriptions via CLI:
php bin/console insightly:webhook:subscribe contact.created
Symfony Forms
Use the InsightlyType form type for API-driven forms:
$builder->add('contact', InsightlyType::class, [
'class' => Contact::class,
'api_service' => $insightly,
]);
Event Listeners Sync Insightly data on entity events:
// src/EventListener/InsightlySyncListener.php
public function onContactPersist(Contact $contact, InsightlyService $insightly)
{
$insightly->createContact($contact->toArray());
}
Caching Cache API responses for performance:
# config/packages/cache.yaml
insightly:
cache: cache.adapter.redis
API Rate Limits
try {
$response = $insightly->getContacts();
} catch (RateLimitExceededException $e) {
sleep($e->getRetryAfter());
retry();
}
Authentication Failures
api_key and api_secret are correct and not hardcoded. Use environment variables:
# .env
INSIGHTLY_API_KEY=%env(INSIGHTLY_API_KEY)%
Data Mapping
cekurte_insightly:
custom_fields:
contact:
'custom_field_123' => 'custom_field_name'
Webhook Delays
Enable API Logging
cekurte_insightly:
debug: true
Logs will appear in var/log/insightly.log.
Validate Responses
Check for Insightly’s errors array in responses:
if (isset($response['errors'])) {
throw new \RuntimeException(implode(', ', $response['errors']));
}
Custom Services Extend the base service for domain-specific logic:
class CustomInsightlyService extends InsightlyService
{
public function getActiveContacts()
{
return $this->getContacts(['filter' => ['status' => 'Active']]);
}
}
Event Dispatching Trigger Symfony events for Insightly actions:
$dispatcher->dispatch(new InsightlyEvent('contact.created', $contact));
Custom API Endpoints Add unsupported endpoints via a decorator:
class CustomInsightlyServiceDecorator implements InsightlyServiceInterface
{
public function __construct(private InsightlyService $decorated) {}
public function getCustomEndpoint()
{
return $this->decorated->callApi('GET', '/custom/endpoint');
}
}
Testing Mock the service in tests:
$mock = $this->createMock(InsightlyService::class);
$mock->method('getContact')->willReturn(['id' => 123, 'name' => 'Test']);
How can I help you explore Laravel packages today?