WT AmoCRM library (Joomla) — Core API

WT Amo CRM library - Documentation
Category: Libraries

Core reference for WT AmoCRM (Webtolk\Amocrm): the Amocrm facade, the AmocrmRequest HTTP client, exceptions, traits, and the EntityInterface contract; explains how to safely work with AmoCRM entities inside Joomla.

Documentation for the core classes of the Webtolk\Amocrm library located in lib_webtolk_amocrm/src.

Quick start (recommended path)

use Webtolk\Amocrm\Amocrm;

$amocrm = new Amocrm();

// Retrieve a list of leads
$leads = $amocrm->leads()->getLeads(['limit' => 50]);

// Load a contact by ID
$contact = $amocrm->contacts()->getContactById(123456);

Requirements:

  • The System - WT AmoCRM system plugin is enabled.
  • Plugin parameters include amocrm_domain, amocrm_client_id, amocrm_client_secret, and (for OAuth) amocrm_code.
  • com_ajax is used for the webhook/AJAX entry point.

Class Amocrm

The library facade. In 1.3.0+ the primary workflow is to reach entities through the magic __call() helpers: $amocrm->leads(), $amocrm->contacts(), $amocrm->users(), etc.

Most methods on this class are marked as deprecated as of 1.3.0 and remain only for backward compatibility. Prefer the entity classes exposed via __call() and AmocrmRequest.

Key methods

  • __construct() — loads the library language files and instantiates AmocrmRequest.
  • getRequest(): AmocrmRequest — returns the request object (useful for low-level calls).
  • __call(string $name, array $_): EntityInterface — creates an entity instance from Webtolk\Amocrm\Entities.

Deprecated methods (1.3.0, slated for removal in 2.0)

Use the entity equivalents:

  • getAccountInfo() > account()->getAccountInfo()
  • getLeadById() > leads()->getLeadById()
  • createLeads() > leads()->createLeads()
  • createLeadsComplex() > leads()->createLeadsComplex()
  • getTags() > tags()->getTags()
  • getLeadsPiplines() > leads()->getLeadsPiplines()
  • getCustomFields() > customfields()->getCustomFields()
  • getContactsCustomFields() > customfields()->getContactsCustomFields()
  • getCompaniesCustomFields() > customfields()->getCompaniesCustomFields()
  • getCustomersCustomFields() > customfields()->getCustomersCustomFields()
  • getContacts() > contacts()->getContacts()
  • addContacts() > contacts()->addContacts()
  • getUserById() > users()->getUserById()
  • getNotes() > notes()->getNotes()
  • addNotes() > notes()->addNotes()

Token management helpers (authorize, setToken, storeTokenData, etc.) are deprecated as well.

Class AmocrmRequest

Low-level HTTP client with authorization, token cache, and error handling.

Core methods

  • getResponse(string $endpoint, ?array $data, string $request_method = 'POST', string $content_type = 'application/x-www-form-urlencoded', bool $custom_endpoint = false): object 
    • Executes a REST call against AmoCRM.
    • If $custom_endpoint = true, the path is used “as is” (without the /api/v4 prefix).
    • Returns the response object or an error object { error_code, error_message }.
  • canDoRequest(): bool - Confirms that credentials and token are present.
  • getPluginParams(): Registry - Reads system/wt_amocrm plugin parameters.
  • getAmoCRMHost(): Uri - Builds a Uri for the AmoCRM domain with enforced https.
  • Token helpers:
    • setToken(), setTokenType(), setTokenExpiresIn()
    • storeTokenData() — caches the token in Joomla.
    • storeRefreshToken() — saves the refresh token back to the library parameters.

Facts

  • Supports token_type = long_term (reads long_term_token).
  • Optionally throttles calls when avoid_rest_api_limits_exceeding = 1 (150 ms sleep).
  • Logs errors to lib_webtolk_amo_crm.log.php.

Sample low-level request

use Webtolk\Amocrm\Amocrm;

$amocrm = new Amocrm();
$request = $amocrm->getRequest();

// Retrieve account information
$account = $request->getResponse('/account', null, 'GET', 'application/json');

Exceptions

  • AmocrmException — the library’s general exception.
  • AmocrmClientException — deprecated (1.3.0).

Traits

  • LogTrait
    • saveToLog(string $data, string $priority = 'NOTICE', string $log_name = 'lib_webtolk_amo_crm') - Writes to logs/{log_name}.log.php and pushes a Joomla message.
  • DataErrorTrait
    • receivedEmptyData() — builds a standard error object.
    • wrongEntityType() — builds an error when the entity type is invalid.

Interface EntityInterface

Minimum contract: the constructor accepts an AmocrmRequest.

public function __construct(AmocrmRequest $request);

WebTolk Joomla Extensions

102 Extensions
12 Categories
519 Versions released
655032 Downloads