This package implements an API client with support for basic entities and authorization via the OAuth 2.0 protocol in amoCRM. PHP version no lower than 7.1 is required to work.
JSON file with tokens is stored in the location specified by the user. The JSON file itself is the following structure:
{
"access_token": ...,
"refresh_token": ...,
"token_type": ...,
"begin_in": ...,
"expires_in": ...,
}
If a JSON file with Refresh Token exists, then the following construction is used (If no code is passed, the Refresh method will be called. If passed, the Auth method will be called.)
use App\Client\AmoApiClient;
$client = new AmoApiClient(
$subDomain,
$client_id,
$client_secret,
$redirect_uri
);
If this is the first run, then the following construction is used
use App\Client\AmoApiClient;
$client = new AmoApiClient(
$subDomain,
$client_id,
$client_secret,
$redirect_uri,
$code
);
// OR
$client = new AmoApiClient(
$subDomain,
$client_id,
$client_secret,
$redirect_uri
);
$client->setAuthCode($code);
try {
$tokens = $client->getToken();
} catch (Exception $exception){
echo $exception;
}
try{
$leads = $client->leads()->getAll([]);
print_r($leads);
} catch (Exception $exception){
echo $exception;
}
try {
$lead = $client->leads()->create()->getById(28643682);
} catch (Exception $exception){
echo $exception;
}
try{
$lead = $client->leads()->create();
$lead->name = "VTestNew213152224";
$lead->price = 321;
print_r($lead->save());
} catch (Exception $exception){
echo $exception;
}
try {
$lead = $client->leads()->create();
$lead->id = 28709597;
$lead->name = "APVTestUpdate32";
$lead->price = 123;
print_r($lead->update());
} catch (Exception $exception){
echo $exception;
}
try {
$lead = $client->leads()->create()->getById(28709597);
$note = $lead->newNote();
$note->note_type = NoteConstants::NOTE_TYPE_COMMON;
$note->text = "New test note";
print_r($lead->addNote($note));
} catch (Exception $exception){
echo $exception;
}
try{
$contact = $client->contacts()->getAll([]);
print_r($contact);
}catch (Exception $exception){
echo $exception;
}
try {
$contact = $client->contacts()->create()->getById(46050921);
print_r($contact->getFieldsAsArray());
} catch (Exception $exception){
echo $exception;
}
try{
$contact = $client->contacts()->create();
$contact->name = "APVTestNewTestContact";
print_r($contact->save());
} catch (Exception $exception){
echo $exception;
}
try {
$contact = $client->contacts()->create();
$contact->id = 46102629;
$contact->name = "APVTestNewContactUpdate!";
print_r($contact->update());
} catch (Exception $exception){
echo $exception;
}
try {
$contact = $client->contacts()->create()->getById(46102629);
$note = $contact->newNote();
$note->note_type = NoteConstants::NOTE_TYPE_COMMON;
$note->text = "New test note to ContactModel";
print_r($contact->addNote($note));
} catch (Exception $exception){
echo $exception;
}
try{
$company = $client->company()->getAll([]);
print_r($company);
}catch (Exception $exception){
echo $exception;
}
try {
$company = $client->company()->create()->getById(46050853);
print_r($company->getFieldsAsArray());
} catch (Exception $exception){
echo $exception;
}
try{
$company = $client->company()->create();
$company->name = "APVTestNewCompany";
print_r($company->save());
} catch (Exception $exception){
echo $exception;
}
try {
$company = $client->company()->create();
$company->id = 46050853;
$company->name = "APVTestNewCompanyUpdate";
print_r($company->update());
} catch (Exception $exception){
echo $exception;
}
try {
$company = $client->company()->create()->getById(46102613);
$note = $company->newNote();
$note->note_type = NoteConstants::NOTE_TYPE_COMMON;
$note->text = "New test note to CompanyModel!";
print_r($company->addNote($note));
} catch (Exception $exception){
echo $exception;
}
try{
$customer = $client->customers();
print_r($customer->getAll([]));
}catch (Exception $exception){
echo $exception;
}
try {
$customer = $client->customers()->create()->getById(183665);
print_r($customer->getFieldsAsArray());
} catch (Exception $exception){
echo $exception;
}
try{
$customer = $client->customers()->create();
$customer->name = "!APVTestCustomer";
print_r($customer->save()->getFieldsAsArray());
} catch (Exception $exception){
echo $exception;
}
try {
$customer = $client->customers()->create();
$customer->id = 187873;
$customer->name = "APVTestCustomerUpdate!";
print_r($customer->update());
} catch (Exception $exception){
echo $exception;
}
try {
$customer = $client->customers()->create()->getById(187873);
$note = $customer->newNote();
$note->note_type = NoteConstants::NOTE_TYPE_COMMON;
$note->text = "New test note to CustomerModel";
print_r($customer->addNote($note));
} catch (Exception $exception){
echo $exception;
}
try{
$task = $client->task();
print_r($task->getAll([]));
}catch (Exception $exception){
echo $exception;
}
try {
$task = $client->task()->create()->getById(46510275);
print_r($task);
} catch (Exception $exception){
echo $exception;
}
try{
$task = $client->task()->create();
$task->task_type_id = TaskConstants::TASK_TYPE_CONTACT;
$task->text = "Test task for 28643682";
$task->entity_id = 28643682;
$task->entity_type = "leads";
$task->complete_till = time() + 3600;
print_r($task->save());
} catch (Exception $exception){
echo $exception;
}
try {
$task = $client->task()->create()->getById(50989199);
$task->task_type_id = TaskConstants::TASK_TYPE_MEETING;
$task->text = "Update task for 28643682";
print_r($task->update());
} catch (Exception $exception){
echo $exception;
}
try{
$user = $client->users()->getAllUsers([]);
print_r($user);
} catch (Exception $exception){
echo $exception;
}
try{
$user = $client->users()->getAllRoles([]);
print_r($user);
} catch (Exception $exception){
echo $exception;
}
try{
$user = $client->users()->create()->getUserById(123);
print_r($user);
} catch (Exception $exception){
echo $exception;
}
try{
$user = $client->users()->create()->getRoleById(123);
print_r($user);
} catch (Exception $exception){
echo $exception;
}