Companies API
FluentCRM Core Developer GuideThe Companies API provides methods for creating, finding, and managing company records, and linking them to contacts.
Initialization
$companyApi = FluentCrmApi('companies');Returns an instance of FluentCrm\App\Api\Classes\Companies.
No query proxy methods
Unlike the Contacts, Tags, and Lists APIs, the Companies API does not support all(), get(), find(), first(), paginate(), or getInstance(). To run custom queries on companies, use the Company model directly:
$companies = \FluentCrm\App\Models\Company::where('status', 'active')->get();Methods
getCompany()
Find a single company by ID or email address, with optional eager-loaded relationships.
$company = $companyApi->getCompany($idOrEmail, $with = []);Parameters
$idOrEmailint|string— Company ID (integer) or email address (string)$witharray— Relationships to eager-load (e.g.,['subscribers', 'owner', 'notes'])
Returns false | Company
INFO
When passing a string, this searches by the company's email field, not by name. To find a company by name, query the model directly:
$company = \FluentCrm\App\Models\Company::where('name', 'Acme Corp')->first();Example:
$company = $companyApi->getCompany(15, ['subscribers', 'owner']);
// By email
$company = $companyApi->getCompany('[email protected]');createOrUpdate()
Create a new company or update an existing one. Matches existing companies by id (if provided) or email.
$company = $companyApi->createOrUpdate($data);Parameters
$dataarray— Company data. Must includenamefor creation. Can includecustom_valuesandowner_id.
Returns false | Company
Fires fluent_crm/company_created or fluent_crm/company_updated action hooks.
If owner_id is provided, the owner contact is automatically attached to the company.
Example:
$company = $companyApi->createOrUpdate([
'name' => 'Acme Corp',
'email' => '[email protected]',
'industry' => 'Technology',
'owner_id' => 12,
'custom_values' => [
'annual_revenue' => '1000000',
]
]);attachContactsByIds()
Link contacts to companies by their IDs.
$result = $companyApi->attachContactsByIds($contactIds, $companyIds);Parameters
$contactIdsarray— Array of subscriber IDs$companyIdsarray— Array of company IDs
Returns false|array — On success: ['companies' => Collection, 'subscribers' => Collection]
Example:
$result = $companyApi->attachContactsByIds([12, 38], [1, 2]);detachContactsByIds()
Remove relationships between contacts and companies.
$result = $companyApi->detachContactsByIds($contactIds, $companyIds);Parameters
$contactIdsarray— Array of subscriber IDs$companyIdsarray— Array of company IDs
Returns false|array — On success: ['companies' => Collection, 'last_primary_company_id' => int|false]
Example:
$result = $companyApi->detachContactsByIds([12, 38], [1, 2]);Querying Companies Directly
Since the Companies API doesn't provide query proxy methods, use the Company model for advanced queries:
use FluentCrm\App\Models\Company;
// Get all active companies
$companies = Company::where('status', 'active')->get();
// Find by ID
$company = Company::find(15);
// Search by name
$companies = Company::where('name', 'LIKE', '%Acme%')->get();
// Paginate
$paginated = Company::paginate(15);
// With relationships
$company = Company::with(['subscribers', 'owner'])->find(15);Source: app/Api/Classes/Companies.php