PHP code example of sergeybruhin / nano-crm-client
1. Go to this page and download the library: Download sergeybruhin/nano-crm-client 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/ */
sergeybruhin / nano-crm-client example snippets
use NanoCrm\Client\NanoCrmClient;
use NanoCrm\Client\Dto\CreateLeadInput;
$client = NanoCrmClient::create(
baseUrl: 'http://nano-crm-api',
token: 'your-service-token',
timeout: 10,
);
$lead = $client->leads()->create(new CreateLeadInput(
contact: ['full_name' => 'Ivan Petrov', 'phone' => '+79001234567'],
source: 'example.com',
type: 'callback',
));
echo $lead->uuid;
$leads = $client->leads();
// Create
$lead = $leads->create(new CreateLeadInput(
contact: ['full_name' => 'Ivan Petrov', 'phone' => '+79001234567'],
source: 'example.com',
type: 'callback',
form: ['page' => '/contacts'], // optional
utm: ['utm_source' => 'google'], // optional
meta: ['ip' => '1.2.3.4'], // optional
formKey: 'callback-v2', // optional
isTest: false,
sentAt: new DateTimeImmutable(), // optional
));
// Find
$lead = $leads->find('019602a0-0000-7000-8000-000000000001');
// Update
$lead = $leads->update($lead->uuid, new UpdateLeadInput(source: 'acme.example.com'));
// Delete (soft)
$leads->delete($lead->uuid);
$contacts = $client->contacts();
// Create
$contact = $contacts->create(new CreateContactInput(
fullName: 'Ivan Petrov',
primaryPhoneNumber: '+79001234567',
primaryEmail: '[email protected] ', // optional
));
// Find
$contact = $contacts->find('019602a0-0000-7000-8000-000000000002');
// Update
$contact = $contacts->update($contact->uuid, new UpdateContactInput(
primaryEmail: '[email protected] ',
));
// Delete (soft)
$contacts->delete($contact->uuid);
use NanoCrm\Client\Exceptions\AuthenticationException;
use NanoCrm\Client\Exceptions\NotFoundException;
use NanoCrm\Client\Exceptions\UnprocessableException;
use NanoCrm\Client\Exceptions\NanoCrmException;
try {
$lead = $client->leads()->find($uuid);
} catch (NotFoundException $e) {
// 404 — not found or deleted
} catch (UnprocessableException $e) {
$errors = $e->errors(); // array<string, string[]>
} catch (AuthenticationException $e) {
// 401 — check token
} catch (NanoCrmException $e) {
// other API error
}