Tiny lib for amoCRM API
This is DEV version of library so Author is not responsible of any damage, both direct and indirect, that may cause using of this library.
For installing add this to your composer.json
:
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "git@github.com:KikyTokamuro/Amoapi"
}
],
"require": {
"kikytokamuro/amoapi": "dev-origin/dev"
}
And run command:
composer require kikytokamuro/amoapi
When receiving tokens, they are written to "tokens.json".
Which can be set via:
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
"tokens.json" // <---
);
tokens.json:
{
"access_token":"access_token",
"refresh_token":"refresh_token",
"expires_in":86400,
"receipt_date":1626683782,
"expires_date":1626770182
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$tokens = $client->getTokensByCode("code"); // array
print_r($tokens);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$tokens = $client->getTokensByRefreshToken("refreshToken"); // array
print_r($tokens);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$filter = [
"page" => 0,
"limit" => 5
];
try {
$leads = $client->leads()->getAll($filter); // array
print_r($leads);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$lead = $client->leads()->getById(28091207); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$lead = $client->leads()->getById(28091207); // array
} catch (AmoapiException $e) {
echo $e;
}
$lead["name"] = "new name";
$lead["price"] = 1111;
try {
print_r($client->leads()->update([$lead])); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$lead = [["name" => "new lead", "price" => 1111]];
try {
print_r($client->leads()->createNew($lead)); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$note = [
"note_type" => "common",
"text" => "test note"
];
try {
print_r($client->leads()->addNoteById(28091207, $note));
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$filter = [
"page" => 0,
"limit" => 50
];
try {
$tasks = $client->tasks()->getAll($filter); // array
print_r($tasks);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$task = [
"task_type_id" => 1,
"text" => "Test task for 28144531",
"complete_till" => 1588885140,
"entity_id" => 28144531,
"entity_type" => "leads",
"request_id" => "example"
];
try {
print_r($client->tasks()->createNew($task));
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$filter = [
"page" => 0,
"limit" => 50
];
try {
$contacts = $client->contacts()->getAll($filter); // array
print_r($contacts);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$contact = $client->contacts()->getById(45552657); // array
print_r($contact);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$contact = $client->contact()->getById(28091207); // array
} catch (AmoapiException $e) {
echo $e;
}
$contact["name"] = "new name";
$contact["price"] = 1111;
try {
print_r($client->contacts()->update([$contact])); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$contact = [["name" => "new contact"]];
try {
print_r($client->contacts()->createNew($contact)); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$note = [
"note_type" => "common",
"text" => "test note"
];
try {
print_r($client->contacts()->addNoteById(28091207, $note))
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$filter = [
"page" => 0,
"limit" => 50
];
try {
$companies = $client->companies()->getAll($filter); // array;
print_r($companies);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$company = $client->companies()->getById(45607457); // array
print_r($company);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$company = $client->companies()->getById(45607457); // array
} catch (AmoapiException $e) {
echo $e;
}
$company["name"] = "update company";
try {
print_r($client->companies()->update([$contact])); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$company = [["name" => "new company"]];
try {
print_r($client->companies()->createNew($company)); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$note = [
"note_type" => "common",
"text" => "test note"
];
try {
print_r($client->companies()->addNoteById(45607457, $note));
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$filter = [
"page" => 0,
"limit" => 50
];
try {
$customers = $client->customers()->getAll($filter); // array
print_r($customers);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$customer = $client->customers()->getById(183435); // array
print_r($customer);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$customer = $client->customers()->getById(183435); // array
} catch (AmoapiException $e) {
echo $e;
}
$customer["name"] = "update customer";
try {
print_r($client->customers()->update([$customer])); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$customer = [["name" => "new company"]];
try {
print_r($client->customers()->createNew($customer)); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$note = [
"note_type" => "common",
"text" => "test note"
];
try {
print_r($client->customers()->addNoteById(183435, $note));
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$filter = [
"page" => 0,
"limit" => 50
];
try {
$users = $client->users()->getAll($filter); // array
print_r($users);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$user = $client->users()->getById(6928032); // array
print_r($user);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$filter = [
"page" => 0,
"limit" => 50
];
try {
$roles = $client->roles()->getAllRoles($filter); // array
print_r($roles);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$role = $client->roles()->getRoleById(56320); // array
print_r($role);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$info = $client->account()->getInfo(); // array
print_r($info);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$filter = [
"page" => 0,
"limit" => 50
];
try {
$catalogs = $client->catalogs()->getAll($filter); // array
print_r($catalogs);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$catalog = $client->catalogs()->getById(2419); // array
print_r($catalog);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$catalog = [["name" => "new catalog"]];
try {
print_r($client->catalogs()->createNew($catalog)); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$catalog = $client->catalogs()->getById(2419); // array
} catch (AmoapiException $e) {
echo $e;
}
$catalog["name"] = "update catalog";
try {
print_r($client->catalogs()->update([$catalog])); // array
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$filter = [
"page" => 0,
"limit" => 50
];
try {
$elements = $client->catalogs()->getAllElements(1989, $filter); // array
print_r($elements);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$element = $client->catalogs()->getElementById(1989, 953789); // array
print_r($element);
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
$element = [["name" => "new element"]];
try {
print_r($client->catalogs()->createNewElement(1989, $catalog));
} catch (AmoapiException $e) {
echo $e;
}
use Amoapi\Client\AmoapiClient;
use Amoapi\Exception\AmoapiException;
$client = new AmoapiClient(
"subdomain",
"client_id",
"client_secret",
"redirect_url",
);
try {
$client->getTokensByCode("code");
} catch (AmoapiException $e) {
echo $e;
}
try {
$element = $this->client->catalogs()->getElementById(1989, 953789);
} catch (AmoapiException $e) {
echo $e;
}
$element["name"] = "new name";
// Delete not expected fields
unset($element["created_by"]);
unset($element["updated_by"]);
unset($element["custom_fields_values"][2]["values"][0]["enum_code"]);
try {
print_r($this->client->catalogs()->updateElement(1989, [$element]));
} catch (AmoapiException $e) {
echo $e;
}