PHP code example of salesoftech / amocrm-api-php-salesoftech

1. Go to this page and download the library: Download salesoftech/amocrm-api-php-salesoftech 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/ */

    

salesoftech / amocrm-api-php-salesoftech example snippets


use SalesOfTech\AmoCRM\SoftAmoClient;
use SalesOfTech\AmoCRM\Storage\SqlTokenStorage;

$pdo = new PDO(
    'mysql:host=127.0.0.1;dbname=soft;charset=utf8mb4',
    'user',
    'pass',
    [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);

// Storage will automatically create table `amocrm_api_php_salesoftech_tokens` if it does not exist
$storage = new SqlTokenStorage($pdo);

$amo = (new SoftAmoClient($storage))
    ->setRedirectUri('https://example.com/amocrm/oauth/callback');

// Get client for a specific company (tenant)
$client = $amo->getClient(1);

// Use standard amocrm/amocrm-api-php services
$leadsService = $client->leads();
$leads        = $leadsService->get();

$client = $amo->authorize(
    companyId:    1,
    integrationId:'CLIENT_ID',
    secret:       'CLIENT_SECRET',
    baseDomain:   'example.amocrm.ru',
    authCode:     $_GET['code']
);

$storage = new FileTokenStorage(__DIR__ . '/amocrm_tokens');
$amo = (new SoftAmoClient($storage))->setRedirectUri('https://example.com/callback');
$client = $amo->getClient(1);

$client1 = $amo->getClient(1);
$client3 = $amo->getClient(3);
$client7  = $amo->getClient(7);

$storage = new SqlTokenStorage($pdo);
$amo = (new SoftAmoClient($storage))->setRedirectUri('https://example.com/callback');
$client = $amo->getClient(1);

$client = $amo->authorize(
    companyId: 1,
    integrationId:'CLIENT_ID',
    secret:'CLIENT_SECRET',
    baseDomain:'example.amocrm.ru',
    authCode:$_GET['code']
);

$storage = new FileTokenStorage(__DIR__.'/tokens');
$amo = (new SoftAmoClient($storage))->setRedirectUri('https://example.com/callback');
$client = $amo->getClient(1);

$client1 = $amo->getClient(1);
$client3 = $amo->getClient(3);
$client7  = $amo->getClient(7);