-
-
Notifications
You must be signed in to change notification settings - Fork 0
Sideloading
How to load related data in a single API request.
Sideloading lets you include related resources in the same response instead of making separate API calls for each one. This reduces round trips and API usage.
// β Without sideloading β 3 API calls
$company = Teamleader::companies()->info('company-uuid');
$user = Teamleader::users()->info($company['data']['responsible_user']['id']);
// β
With sideloading β 1 API call
$company = Teamleader::companies()
->with('responsible_user')
->info('company-uuid');The Teamleader API accepts includes (plural) as the POST body key for both .list and .info endpoints. The SDK handles this translation automatically.
You should always use one of the SDK patterns below. Do not set includes directly in a params array β use include in the options array or the with() method, and the SDK will send the correct key.
Chain with() before info() or list(). Accepts a comma-separated string or an array.
// Single relationship
$company = Teamleader::companies()
->with('custom_fields')
->info('company-uuid');
// Multiple relationships β comma-separated string
$company = Teamleader::companies()
->with('custom_fields,responsible_user,addresses')
->info('company-uuid');
// Multiple relationships β array
$company = Teamleader::companies()
->with(['custom_fields', 'responsible_user'])
->info('company-uuid');
// Chaining
$company = Teamleader::companies()
->with('custom_fields')
->with('responsible_user')
->info('company-uuid');
// Works with list() too
$companies = Teamleader::companies()
->with('custom_fields,price_list')
->list(['status' => 'active']);Pass include as part of the options (second argument to list(), or second argument to info()):
// list()
$companies = Teamleader::companies()->list([], [
'include' => 'custom_fields,responsible_user',
]);
// info()
$company = Teamleader::companies()->info('company-uuid', 'custom_fields,responsible_user');Not every resource supports sideloading. Resources with supportsSideloading: false will ignore the includes parameter. Check individual resource docs for their available includes.
| Include | Description |
|---|---|
custom_fields |
Custom field values |
price_list |
Assigned price list |
responsible_user |
Responsible user |
addresses |
Address records |
business_type |
Business type reference |
tags |
Associated tags |
| Include | Description |
|---|---|
custom_fields |
Custom field values |
price_list |
Assigned price list |
responsible_user |
Responsible user |
addresses |
Address records |
| Include | Description |
|---|---|
custom_fields |
Custom field values |
responsible_user |
Responsible user |
| Include | Description |
|---|---|
custom_fields |
Custom field values |
| Include | Description |
|---|---|
custom_fields |
Custom field values |
suppliers |
Associated suppliers |
| Include | Description |
|---|---|
custom_fields |
Custom field values |
Custom fields are not included by default. Request them explicitly and iterate over the returned array:
$companies = Teamleader::companies()->list([], [
'page_size' => 100,
'include' => 'custom_fields',
]);
foreach ($companies['data'] as $company) {
foreach ($company['custom_fields'] ?? [] as $field) {
$definitionId = $field['definition']['id']; // UUID
$value = $field['value'];
}
}Custom field structure in the response:
{
"definition": {
"type": "customFieldDefinition",
"id": "bf6765de-56eb-40ec-ad14-9096c5dc5fe1"
},
"value": "some value"
}$company = Teamleader::companies()
->with('responsible_user,addresses,custom_fields')
->info('company-uuid');
// Sideloaded object relationship
$userId = $company['data']['responsible_user']['id'] ?? null;
// Sideloaded array relationship
foreach ($company['data']['addresses'] ?? [] as $address) {
echo $address['line_1'];
}
// Custom fields
foreach ($company['data']['custom_fields'] ?? [] as $field) {
$id = $field['definition']['id'];
$value = $field['value'];
}Only request the relationships you actually need:
// β Requesting everything unnecessarily
$company = Teamleader::companies()
->with('custom_fields,price_list,responsible_user,addresses,business_type,tags')
->info('company-uuid');
// β
Only what is needed
$company = Teamleader::companies()
->with('custom_fields')
->info('company-uuid');Prefer sideloading in list() calls over calling info() per record:
// β N+1 calls
foreach ($companies['data'] as $company) {
$full = Teamleader::companies()->info($company['id'], 'custom_fields');
}
// β
One call
$companies = Teamleader::companies()
->with('custom_fields')
->list([], ['page_size' => 100]);Last Updated: August 2026 β’ SDK Version: 2.2.2 β’ Made with β€οΈ by MCore Services
- Departments
- Users
- Teams
- Custom Fields
- Work Types
- Document Templates
- Currencies
- Notes
- Email Tracking
- Closing Days
- Day Off Types
- Days Off
- User Schedules
- Invoices
- Credit Notes
- Subscriptions
- Payment Methods
- Payment Terms
- Tax Rates
- Withholding Tax Rates
- Commercial Discounts
Next Gen Projects
Legacy Projects