bisonlab/sugarcrm-bundle
Symfony2 bundle to access SugarCRM REST v10 via the spinegar SugarCRM7 API wrapper. Configure base URL and credentials, then use the wrapper directly or through a NoOrmBundle-style adapter for more structured integration.
Installation
composer require bisonlab/sugarcrm-bundle
Add to AppKernel.php:
new BisonLab\SugarCrmBundle\BisonLabSugarCrmBundle(),
Configure
Add to config/packages/sugarcrm.yaml (or config.yml):
parameters:
sugarcrm_base_url: "http://your-sugar-instance.com"
sugarcrm_username: "your_username"
sugarcrm_password: "your_password"
Choose a service config:
imports:
- { resource: "@BisonLabSugarCrmBundle/Resources/config/services_wrapper.yml" } # Direct wrapper
# OR
- { resource: "@BisonLabSugarCrmBundle/Resources/config/services.yml" } # NoOrmBundle integration
First Use Case Inject the service and call SugarCRM API:
use BisonLab\SugarCrmBundle\Service\SugarService;
class MyController extends AbstractController {
public function __construct(private SugarService $sugarService) {}
public function listContacts() {
$contacts = $this->sugarService->get('Contacts');
$results = $contacts->getEntries(['name' => 'John']);
return $this->json($results);
}
}
Service Injection
public function __construct(private SugarService $sugarService) {}
Access modules directly:
$accounts = $this->sugarService->get('Accounts');
$account = $accounts->getEntry(123); // Fetch single record
Common Workflows Create/Update Records:
$account = $this->sugarService->get('Accounts');
$account->setEntry([
'name' => 'Acme Corp',
'description' => 'New client',
]);
$account->save();
Querying:
$contacts = $this->sugarService->get('Contacts');
$results = $contacts->getEntries([
'filter' => [
'name' => ['like' => '%Doe%'],
'status' => 'Active',
],
'select_fields' => ['id', 'name', 'email'],
]);
Relationships:
$account = $this->sugarService->get('Accounts')->getEntry(123);
$contacts = $account->getRelated('contacts'); // Load linked contacts
Bulk Operations
Use setEntries() + save() for batch updates:
$accounts = $this->sugarService->get('Accounts');
$accounts->setEntries([
['name' => 'Client A', 'id' => 1],
['name' => 'Client B', 'id' => 2],
]);
$accounts->save();
Entity Mapping
Define a SugarEntity class extending BisonLab\NoOrmBundle\Entity\AbstractEntity:
namespace App\Entity;
use BisonLab\NoOrmBundle\Entity\AbstractEntity;
class SugarContact extends AbstractEntity {
protected $module = 'Contacts';
}
Use in services:
$contact = new SugarContact();
$contact->setName('Jane Doe');
$contact->save();
When to Use Prefer the direct wrapper for simplicity. Use NoOrmBundle only if:
BisonLabNoOrmBundle for other integrations.Authentication Failures
401 Unauthorized or empty responses.sugarcrm_username/sugarcrm_password in parameters.yml. Ensure the user has API access in SugarCRM (Admin > Users > [User] > API Access).Module Not Found
Module [X] not found errors.Accounts vs. account). Use getModuleList() to debug:
$modules = $this->sugarService->getModuleList();
Rate Limiting
504 Gateway Timeout.sleep(1); // Pause between batches
Field Name Mismatches
Invalid field name errors.$metadata = $this->sugarService->get('Contacts')->getMetadata();
Enable API Logging
Add to config/packages/sugarcrm.yaml:
parameters:
sugarcrm_debug: true
Logs will appear in var/log/sugarcrm.log.
Raw API Calls Access the underlying client for debugging:
$client = $this->sugarService->getClient();
$response = $client->request('GET', '/rest/v10/Contacts');
Common HTTP Errors
| Error | Cause | Solution |
|---|---|---|
400 Bad Request |
Malformed payload | Validate data structure (use getMetadata()). |
403 Forbidden |
Insufficient permissions | Check user role in SugarCRM. |
404 Not Found |
Invalid endpoint/module | Verify module name and API version (v10). |
Custom Modules Extend the wrapper for unsupported modules:
$customModule = $this->sugarService->getClient()->getModule('CustomModule');
Event Listeners Use Symfony’s event system to intercept SugarCRM responses:
// config/services.yaml
BisonLab\SugarCrmBundle\EventListener\SugarResponseListener:
tags:
- { name: kernel.event_listener, event: sugarcrm.response, method: onResponse }
Caching Cache frequent queries (e.g., module metadata):
$metadata = $this->sugarService->get('Contacts')->getMetadata();
$this->cache->set('sugar_contacts_metadata', $metadata, 3600);
Async Operations Offload long-running tasks to a queue (e.g., Symfony Messenger):
$this->messageBus->dispatch(new SyncSugarDataMessage($data));
API Version
The bundle defaults to v10. For newer versions, override the client:
# config/services.yaml
BisonLab\SugarCrmBundle\Service\SugarService:
arguments:
$apiVersion: 'v11'
SSL/TLS
If using HTTPS, ensure sugarcrm_base_url includes https:// and SugarCRM’s SSL certificate is valid. For self-signed certs, configure the client:
$client = $this->sugarService->getClient();
$client->setOption('verify', false); // Not recommended for production
How can I help you explore Laravel packages today?