Skip to content

KikyTokamuro/Amoapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Amoapi

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.

Installing

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

What is implemented

Examples

Tokens

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
}

Get access and refresh tokens by code

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;
}

Get access and refresh tokens by refresh token

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;
}

Leads

Get 5 leads from 1 page

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;
}

Get lead by id

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;
}

Update lead

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;
}

Create new lead

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;
}

Add note to lead by id

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;
}

Tasks

Get 50 tasks from 1 page

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;
}

Create task for others entity

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;
}

Contacts

Get all contacts

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;
}

Get contact by id

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;
}

Update contact

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;
}

Create new contact

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;
}

Add note to contact by id

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;
}

Companies

Get all companies

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;
}

Get company by id

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;
}

Update company

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;
}

Create new company

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;
}

Add note to company by id

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;
}

Customers

Get all customers

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;
}

Get customer by id

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;
}

Update customer

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;
}

Create new customer

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;
}

Add note to customer by id

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;
}

Users

Get all users

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;
}

Get user by id

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;
}

Roles

Get all users roles

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;
}

Get role by id

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;
}

Account

Get account info

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;
}

Catalogs

Get all catalogs

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;
}

Get catalog by id

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;
}

Create new catalog

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;
}

Update catalog

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;
}

Get all catalog elements

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;
}

Get catalog element by id

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;
}

Add new element to catalog

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;
}

Update catalog element

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;
}

Releases

No releases published

Packages

No packages published

Languages