PHP code example of contractors-es / php-api
1. Go to this page and download the library: Download contractors-es/php-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
contractors-es / php-api example snippets
ontractorsEs\Api\Api;
$api = new Api(
'https://demo.contractors.es',
'admin',
'admin',
'en',
getenv('API_2FA') ?: ''
);
$company = $api->first('/api/crm/companies');
print_r($company);
$countries = $api->getAll('/api/countries?limit=50');
print_r($countries);
$result = $api->searchAll('/api/crm/companies', [
'filters' => [
[
'type' => 'and',
'field' => 'company_name',
'operator' => 'like',
'value' => '%a%',
],
],
'limit' => 25,
]);
print_r($result);
$createdTask = $api->create('/api/crm/tasks', [
'title' => 'API Task ' . date('c'),
'deadline_date' => date('Y-m-d'),
'deadline_time' => date('H:i'),
'priority' => 1,
]);
$taskId = $createdTask['id'];
$api->update("/api/crm/tasks/{$taskId}", [
'status' => 2,
]);
$location = $api->getFirst('/api/crm/meeting-locations');
$api->post('/api/crm/meetings/batch', [
'resources' => [
[
'title' => 'Batch Meeting #1',
'start' => '2025-11-20 13:00:00',
'end' => '2025-11-20 14:00:00',
'priority' => 1,
'schedule_type' => 'datetime',
'location_id' => $location['id'] ?? null,
],
[
'title' => 'Batch Meeting #2',
'start' => '2025-11-20 5:00 PM',
'end' => '2025-11-20 06:00 PM',
'priority' => 1,
'schedule_type' => 'datetime',
'location_id' => $location['id'] ?? null,
],
],
]);
$contact = $api->getFirst('/api/crm/contacts');
if (!empty($contact)) {
$api->post("/api/crm/tasks/{$taskId}/employees/attach", [
'resources' => [$contact['id']],
]);
}
use ContractorsEs\Api\ApiRequestException;
try {
$api->record('/api/contractors/projects/999999');
} catch (ApiRequestException $e) {
echo 'Status: ' . $e->getStatusCode() . PHP_EOL;
echo 'Response: ' . $e->getResponseBody() . PHP_EOL;
}
$api = new Api($url, $user, $pass, $lang, $twoFactorToken, '/tmp/contractors-api-tokens');
bash
composer