Megaplan CRM Integration with Website
Megaplan is a Russian CRM and task management system, popular in small and medium business. Integration allows automatic deal and lead creation from website requests, contact synchronization, and receiving notifications about CRM changes.
Megaplan API
Megaplan provides REST API. Authentication via Bearer token obtained by exchanging login/password or via API key in account settings.
GET https://your-domain.megaplan.ru/api/v3/deal/list
Authorization: Bearer {access_token}
Creating Deal from Request
$response = Http::withToken($this->getToken())
->post("https://{$this->domain}.megaplan.ru/api/v3/deal/create", [
'data' => [
'contentType' => 'Deal',
'name' => "Request from website: {$request->subject}",
'programId' => ['contentType' => 'DealProgram', 'id' => $this->pipelineId],
'responsible' => ['contentType' => 'Employee', 'id' => $this->defaultManagerId],
'contractor' => ['contentType' => 'Client', 'id' => $contactId],
'extraFields' => [
'Cf12345' => $request->message, // custom field
]
]
]);
Finding or Creating Contact
Before creating deal, need to find contact by email or phone:
// Search for existing contact
$search = Http::withToken($this->getToken())
->post("https://{$this->domain}.megaplan.ru/api/v3/contractor/list", [
'data' => [
'contentType' => 'ContractorFilter',
'email' => $request->email
]
]);
if ($search['data']['meta']['totalCount'] > 0) {
$contactId = $search['data']['list'][0]['id'];
} else {
// Create new
$contact = Http::withToken($this->getToken())
->post("https://{$this->domain}.megaplan.ru/api/v3/client/create", [...]);
$contactId = $contact['data']['id'];
}
Token Obtaining and Refresh
$response = Http::post("https://{$this->domain}.megaplan.ru/api/v3/auth/access_token", [
'username' => env('MEGAPLAN_LOGIN'),
'password' => env('MEGAPLAN_PASSWORD'),
'grant_type' => 'password'
]);
$token = $response['access_token'];
$refreshToken = $response['refresh_token'];
// Store token in cache, refresh via refresh_token
Webhooks from Megaplan
Megaplan supports outgoing webhook notifications when deal status changes. Allows updating request status on site when manager moves deal to another pipeline stage.
Practical Tips
- API Megaplan can be slow (200–500ms) — all requests via queue
- Use token cache (Redis) — don't request token per request
- Log all requests/responses to
crm_logstable for debugging
Integration time: 3–4 days for basic integration (leads + contacts + deals).







