{"id":329162,"date":"2022-02-06T21:00:19","date_gmt":"2022-02-06T21:00:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=329162"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=329162","title":{"rendered":"<span>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f amoCRM \u0441 \u0441\u0430\u0439\u0442\u043e\u043c API<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>AmoCRM \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 CRM, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0435\u0435 API \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0445, \u043f\u043e \u043c\u043e\u0435\u043c\u0443 \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e. \u041f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u0441 \u0441\u0430\u0439\u0442\u0430 \u0432 crm. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CRM \u0424\u043e\u0440\u043c\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0432\u043e\u0438\u0445 \u0434\u0438\u0437\u0430\u0439\u043d\u0435\u0440\u0441\u043a\u0438\u0445 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f. \u0411\u044b\u043b\u043e \u0431\u044b \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u0442\u0430\u0442\u0435\u0439\u043a\u0443 \u0432 \u0433\u0443\u0433\u043b\u0435, \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u044e\u0447 \u0438 \u043d\u0435 \u043f\u0430\u0440\u0438\u0442\u044c\u0441\u044f \u043e\u0441\u043e\u0431\u043e, \u043d\u043e \u043d\u0430 \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0439, \u0433\u0434\u0435-\u0442\u043e \u0432\u0435\u0440\u0441\u0438\u044f api \u0443\u0436\u0435 \u043d\u0435 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0430, \u0433\u0434\u0435-\u0442\u043e  \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430, \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435. \u0412 \u043e\u0431\u0449\u0435\u043c \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c, \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u043e\u043c\u0443 \u0441\u043b\u043e\u0436\u043d\u043e\/\u043b\u0435\u043d\u044c \u0432\u043d\u0438\u043a\u0430\u0442\u044c \u0432 \u0438\u0445 API.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u0443\u0434\u0443 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0434\u0435\u043b\u043a\u0443 \u0432 &#171;\u041d\u0435\u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u043c&#187;, \u043a\u043e\u043d\u0442\u0430\u043a\u0442 \u0438 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u044b \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0443 amo, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u043a\u043e\u0440\u043d\u0435 \u0441\u0430\u0439\u0442\u0430.<br \/>\u0424\u0430\u0439\u043b\u044b \u0432\u043d\u0443\u0442\u0440\u0438:<br \/><em>amo.php<br \/>access.php<br \/>config.php<br \/>get.php<br \/>cookie.txt<br \/>tokens.txt<br \/><\/em>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0439<\/h2>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c AmoCRM, \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 > \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438.<br \/>\u0416\u043c\u0435\u043c &#171;+ \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e&#187; \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e<br \/>\u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0430\u0448 <em>amo.php<\/em> \u0444\u0430\u0439\u043b, \u0441\u0442\u0430\u0432\u0438\u043c \u0433\u0430\u043b\u043e\u0447\u043a\u0443 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438 \u0432\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/p>\n<p><em>P.S. \u041f\u0435\u0440\u0435\u0434 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0447\u0442\u0438\u0442\u0435 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430<\/em><\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"654\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ee\/39d\/9c6\/7ee39d9c6cd1879486626a6e7caddfb3.png\" data-width=\"1063\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f 3 \u043a\u043b\u044e\u0447\u0430 <strong>\u0438 20 \u043c\u0438\u043d\u0443\u0442, \u0447\u0442\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/strong><br \/>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c <em>config.php <\/em>\u0438 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u0442\u0443\u0434\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php $subdomain     = ''; \/\/ \u043f\u043e\u0434\u0434\u043e\u043c\u0435\u043d AmoCRM $client_secret = ''; \/\/ \u0421\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 $client_id     = ''; \/\/ ID \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 $code          = ''; \/\/ \u041a\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 $token_file    = 'tokens.txt'; $redirect_uri  = 'https:\/\/site.com\/amo\/amo.php';<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0434\u043e\u043c\u0435\u043d AmoCRM \u0431\u0435\u0440\u0435\u043c \u0438\u0437 url \u043d\u0430\u0448\u0435\u0439 CRM<br \/>\u0412 <em>$redirect_uri<\/em> \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0432\u043e\u0439 \u0434\u043e\u043c\u0435\u043d \u0441\u0430\u0439\u0442\u0430<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0438\u0434\u0435\u043c \u0432 \u0444\u0430\u0439\u043b <em>auth.php<\/em> \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"php\">&lt;?php require_once 'config.php';  $link = \"https:\/\/$subdomain.amocrm.ru\/oauth2\/access_token\";  $data = [   'client_id'     => $client_id,   'client_secret' => $client_secret,   'grant_type'    => 'authorization_code',   'code'          => $code,   'redirect_uri'  => $redirect_uri, ];  $curl = curl_init(); curl_setopt($curl,CURLOPT_RETURNTRANSFER, true); curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-oAuth-client\/1.0'); curl_setopt($curl,CURLOPT_URL, $link); curl_setopt($curl,CURLOPT_HTTPHEADER, ['Content-Type:application\/json']); curl_setopt($curl,CURLOPT_HEADER, false); curl_setopt($curl,CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl,CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, 2); $out = curl_exec($curl); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); $code = (int)$code;  $errors = [ 301 => 'Moved permanently.',   400 => 'Wrong structure of the array of transmitted data, or invalid identifiers of custom fields.',   401 => 'Not Authorized. There is no account information on the server. You need to make a request to another server on the transmitted IP.',   403 => 'The account is blocked, for repeatedly exceeding the number of requests per second.',   404 => 'Not found.',   500 => 'Internal server error.',   502 => 'Bad gateway.',   503 => 'Service unavailable.' ];  if ($code &lt; 200 || $code > 204) die( \"Error $code. \" . (isset($errors[$code]) ? $errors[$code] : 'Undefined error') );   $response = json_decode($out, true);  $arrParamsAmo = [ \"access_token\"  => $response['access_token'], \"refresh_token\" => $response['refresh_token'], \"token_type\"    => $response['token_type'], \"expires_in\"    => $response['expires_in'], \"endTokenTime\"  => $response['expires_in'] + time(), ];  $arrParamsAmo = json_encode($arrParamsAmo);  $f = fopen($token_file, 'w'); fwrite($f, $arrParamsAmo); fclose($f);  print_r($arrParamsAmo);<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 AmoCRM \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u0432. \u0422\u043e\u043a\u0435\u043d\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b <em>(45-57 \u0441\u0442\u0440\u043e\u043a\u0438)<\/em>, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u0445 \u0432 \u0411\u0414.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0444\u0430\u0439\u043b, https:\/\/site.com\/amo\/auth.php<br \/>\u041a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0439\u043b\u0435 tokens.txt \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<h2>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0430<\/h2>\n<p>Access token \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<br \/>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b <em>access.php<\/em> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"php\">&lt;?php require_once 'config.php';  $dataToken = file_get_contents($token_file); $dataToken = json_decode($dataToken, true);  if ($dataToken[\"endTokenTime\"] &lt; time()) {      $link = \"https:\/\/$subdomain.amocrm.ru\/oauth2\/access_token\";      $data = [         'client_id'     => $client_id,         'client_secret' => $client_secret,         'grant_type'    => 'refresh_token',         'refresh_token' => $dataToken[\"refresh_token\"],         'redirect_uri'  => $redirect_uri,     ];      $curl = curl_init();     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);     curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-oAuth-client\/1.0');     curl_setopt($curl, CURLOPT_URL, $link);     curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type:application\/json']);     curl_setopt($curl, CURLOPT_HEADER, false);     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');     curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);     $out = curl_exec($curl);     $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);     curl_close($curl);      $code = (int)$code;     $errors = [         301 => 'Moved permanently.',         400 => 'Wrong structure of the array of transmitted data, or invalid identifiers of custom fields.',         401 => 'Not Authorized. There is no account information on the server. You need to make a request to another server on the transmitted IP.',         403 => 'The account is blocked, for repeatedly exceeding the number of requests per second.',         404 => 'Not found.',         500 => 'Internal server error.',         502 => 'Bad gateway.',         503 => 'Service unavailable.'     ];      if ($code &lt; 200 || $code > 204) die( \"Error $code. \" . (isset($errors[$code]) ? $errors[$code] : 'Undefined error') );      $response = json_decode($out, true);      $arrParamsAmo = [         \"access_token\"  => $response['access_token'],         \"refresh_token\" => $response['refresh_token'],         \"token_type\"    => $response['token_type'],         \"expires_in\"    => $response['expires_in'],         \"endTokenTime\"  => $response['expires_in'] + time(),     ];      $arrParamsAmo = json_encode($arrParamsAmo);      $f = fopen($token_file, 'w');     fwrite($f, $arrParamsAmo);     fclose($f);      $access_token = $response['access_token'];  } else {     $access_token = $dataToken[\"access_token\"]; }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0411\u0414, \u043f\u0440\u043e\u043f\u0438\u0448\u0438\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0445 \u0438\u0437 \u0411\u0414 <em>(59-61 \u0441\u0442\u0440\u043e\u043a\u0438)<\/em>.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 html \u0444\u043e\u0440\u043c\u044b, \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0443 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 <em>amo.php<\/em> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c amo.php \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"php\">&lt;?php  require_once 'access.php';  $name = '\u0418\u043c\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430'; $phone = '+380123456789'; $email = 'email@gmail.com'; $target = '\u0426\u0435\u043b\u044c'; $company = '\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438';  $custom_field_id = 454021; $custom_field_value = '\u0442\u0435\u0441\u0442';  $ip = '1.2.3.4'; $domain = 'site.com'; $price = 0; $pipeline_id = 5059931; $user_amo = 0;  $utm_source   = ''; $utm_content  = ''; $utm_medium   = ''; $utm_campaign = ''; $utm_term     = ''; $utm_referrer = '';  $data = [     [         \"name\" => $phone,         \"price\" => $price,         \"responsible_user_id\" => $user_amo,         \"pipeline_id\" => $pipeline_id,         \"_embedded\" => [             \"metadata\" => [                 \"category\" => \"forms\",                 \"form_id\" => 1,                 \"form_name\" => \"\u0424\u043e\u0440\u043c\u0430 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435\",                 \"form_page\" => $target,                 \"form_sent_at\" => strtotime(date(\"Y-m-d H:i:s\")),                 \"ip\" => $ip,                 \"referer\" => $domain             ],             \"contacts\" => [                 [                     \"first_name\" => $name,                     \"custom_fields_values\" => [                         [                             \"field_code\" => \"EMAIL\",                             \"values\" => [                                 [                                     \"enum_code\" => \"WORK\",                                     \"value\" => $email                                 ]                             ]                         ],                         [                             \"field_code\" => \"PHONE\",                             \"values\" => [                                 [                                     \"enum_code\" => \"WORK\",                                     \"value\" => $phone                                 ]                             ]                         ],                         [                             \"field_id\" => $custom_field_id,                             \"values\" => [                                 [                                     \"value\" => $custom_field_value                                 ]                             ]                         ]                     ]                 ]             ],             \"companies\" => [                 [                     \"name\" => $company                 ]             ]         ],         \"custom_fields_values\" => [             [                 \"field_code\" => 'UTM_SOURCE',                 \"values\" => [                     [                         \"value\" => $utm_source                     ]                 ]             ],             [                 \"field_code\" => 'UTM_CONTENT',                 \"values\" => [                     [                         \"value\" => $utm_content                     ]                 ]             ],             [                 \"field_code\" => 'UTM_MEDIUM',                 \"values\" => [                     [                         \"value\" => $utm_medium                     ]                 ]             ],             [                 \"field_code\" => 'UTM_CAMPAIGN',                 \"values\" => [                     [                         \"value\" => $utm_campaign                     ]                 ]             ],             [                 \"field_code\" => 'UTM_TERM',                 \"values\" => [                     [                         \"value\" => $utm_term                     ]                 ]             ],             [                 \"field_code\" => 'UTM_REFERRER',                 \"values\" => [                     [                         \"value\" => $utm_referrer                     ]                 ]             ],         ],     ] ];  $method = \"\/api\/v4\/leads\/complex\";  $headers = [     'Content-Type: application\/json',     'Authorization: Bearer ' . $access_token, ];  $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-API-client\/1.0'); curl_setopt($curl, CURLOPT_URL, \"https:\/\/$subdomain.amocrm.ru\".$method); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_COOKIEFILE, 'amo\/cookie.txt'); curl_setopt($curl, CURLOPT_COOKIEJAR, 'amo\/cookie.txt'); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); $out = curl_exec($curl); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); $code = (int) $code; $errors = [     301 => 'Moved permanently.',     400 => 'Wrong structure of the array of transmitted data, or invalid identifiers of custom fields.',     401 => 'Not Authorized. There is no account information on the server. You need to make a request to another server on the transmitted IP.',     403 => 'The account is blocked, for repeatedly exceeding the number of requests per second.',     404 => 'Not found.',     500 => 'Internal server error.',     502 => 'Bad gateway.',     503 => 'Service unavailable.' ];  if ($code &lt; 200 || $code > 204) die( \"Error $code. \" . (isset($errors[$code]) ? $errors[$code] : 'Undefined error') );   $Response = json_decode($out, true); $Response = $Response['_embedded']['items']; $output = 'ID \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u043e\u0432:' . PHP_EOL; foreach ($Response as $v)     if (is_array($v))         $output .= $v['id'] . PHP_EOL; return $output; <\/code><\/pre>\n<p>\u0412 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0443 \u043d\u0430\u0441 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043a\u0443\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u043e\u0440\u043c\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <code>$name = $_POST['name'];<\/code><\/p>\n<p>\u0412 $pipeline_id \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c <strong>id \u0432\u043e\u0440\u043e\u043d\u043a\u0438<\/strong>, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 url crm:<br \/>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b &#171;\u0421\u0434\u0435\u043b\u043a\u0438&#187;, \u0431\u0435\u0440\u0435\u043c id \u043e\u0442\u043a\u0440\u044b\u0432\u0448\u0435\u0439\u0441\u044f \u0432\u043e\u0440\u043e\u043d\u043a\u0438 <strong>(\u0447\u0438\u0441\u043b\u043e \u0432 \u043a\u043e\u043d\u0446\u0435 url)<\/strong>, \u043b\u0438\u0431\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e.<\/p>\n<p>\u041a $user_amo \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435. \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435.<\/p>\n<p>\u041c\u0430\u0441\u0441\u0438\u0432 $data \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043d\u0430 \u0441\u0432\u043e\u0435 \u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0435, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/www.amocrm.ru\/developers\/content\/crm_platform\/leads-api#leads-complex-add\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 id \u043f\u043e\u043b\u0435\u0439<\/h2>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u043e\u043b\u0435\u0439, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0432\u0441\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0447\u0435\u0440\u0435\u0437 GET \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0430 \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043d\u0443\u0436\u043d\u044b\u0435 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435. \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b <em>get.php<\/em> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0435\u0433\u043e:<\/p>\n<pre><code class=\"php\">&lt;?php require_once 'config.php';  function printLink($method, $title, $subdomain) {     echo '&lt;br>';     echo \"&lt;a href='https:\/\/$subdomain.amocrm.ru\/$method' target='_blank'>$title&lt;\/a>\";     echo '&lt;br>'; }  printLink('api\/v4\/leads\/custom_fields', '\u0421\u043f\u0438\u0441\u043e\u043a utm \u043c\u0435\u0442\u043e\u043a', $subdomain); printLink('api\/v4\/users', '\u0421\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439', $subdomain); printLink('api\/v4\/contacts\/custom_fields', '\u0421\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u0435\u0439 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430', $subdomain);  echo '&lt;br>'; echo \"&lt;a href='https:\/\/www.amocrm.ru\/developers\/content\/crm_platform\/custom-fields' target='_blank'>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f&lt;\/a>\"; echo '&lt;br>';<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0444\u0430\u0439\u043b: https:\/\/site.com\/amo\/get.php<br \/>\u0412\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u0441\u0441\u044b\u043b\u043e\u043a, \u043f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0441\u043f\u0438\u0441\u043e\u043a id \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e\u043b\u0435\u0439 \u0434\u043b\u044f utm \u043c\u0435\u0442\u043e\u043a, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u043e\u0432. \u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435.<br \/>\u0412\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 $user_amo. \u0421\u044e\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u043f\u0438\u0441\u0430\u0442\u044c id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430 \u0441\u0434\u0435\u043b\u043a\u0443.<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043b\u0438\u0434\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u043d\u0435\u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u0435, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u0442\u0430\u043a\u0442, \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u0433\u043e \u0438\u043c\u044f, \u0442\u0435\u043b\u0435\u0444\u043e\u043d, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f, utm \u043c\u0435\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432 $data \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/650019\/\"> https:\/\/habr.com\/ru\/post\/650019\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>AmoCRM \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 CRM, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0435\u0435 API \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0445, \u043f\u043e \u043c\u043e\u0435\u043c\u0443 \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e. \u041f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u0441 \u0441\u0430\u0439\u0442\u0430 \u0432 crm. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CRM \u0424\u043e\u0440\u043c\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0432\u043e\u0438\u0445 \u0434\u0438\u0437\u0430\u0439\u043d\u0435\u0440\u0441\u043a\u0438\u0445 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f. \u0411\u044b\u043b\u043e \u0431\u044b \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u0442\u0430\u0442\u0435\u0439\u043a\u0443 \u0432 \u0433\u0443\u0433\u043b\u0435, \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u044e\u0447 \u0438 \u043d\u0435 \u043f\u0430\u0440\u0438\u0442\u044c\u0441\u044f \u043e\u0441\u043e\u0431\u043e, \u043d\u043e \u043d\u0430 \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0439, \u0433\u0434\u0435-\u0442\u043e \u0432\u0435\u0440\u0441\u0438\u044f api \u0443\u0436\u0435 \u043d\u0435 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0430, \u0433\u0434\u0435-\u0442\u043e  \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430, \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435. \u0412 \u043e\u0431\u0449\u0435\u043c \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c, \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u043e\u043c\u0443 \u0441\u043b\u043e\u0436\u043d\u043e\/\u043b\u0435\u043d\u044c \u0432\u043d\u0438\u043a\u0430\u0442\u044c \u0432 \u0438\u0445 API.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u0443\u0434\u0443 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0434\u0435\u043b\u043a\u0443 \u0432 &#171;\u041d\u0435\u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u043c&#187;, \u043a\u043e\u043d\u0442\u0430\u043a\u0442 \u0438 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u044b \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0443 amo, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u043a\u043e\u0440\u043d\u0435 \u0441\u0430\u0439\u0442\u0430.<br \/>\u0424\u0430\u0439\u043b\u044b \u0432\u043d\u0443\u0442\u0440\u0438:<br \/><em>amo.php<br \/>access.php<br \/>config.php<br \/>get.php<br \/>cookie.txt<br \/>tokens.txt<br \/><\/em>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0439<\/h2>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c AmoCRM, \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 > \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438.<br \/>\u0416\u043c\u0435\u043c &#171;+ \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e&#187; \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e<br \/>\u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0430\u0448 <em>amo.php<\/em> \u0444\u0430\u0439\u043b, \u0441\u0442\u0430\u0432\u0438\u043c \u0433\u0430\u043b\u043e\u0447\u043a\u0443 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438 \u0432\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/p>\n<p><em>P.S. \u041f\u0435\u0440\u0435\u0434 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0447\u0442\u0438\u0442\u0435 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430<\/em><\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f 3 \u043a\u043b\u044e\u0447\u0430 <strong>\u0438 20 \u043c\u0438\u043d\u0443\u0442, \u0447\u0442\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/strong><br \/>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c <em>config.php <\/em>\u0438 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u0442\u0443\u0434\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php $subdomain     = ''; \/\/ \u043f\u043e\u0434\u0434\u043e\u043c\u0435\u043d AmoCRM $client_secret = ''; \/\/ \u0421\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 $client_id     = ''; \/\/ ID \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 $code          = ''; \/\/ \u041a\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 $token_file    = 'tokens.txt'; $redirect_uri  = 'https:\/\/site.com\/amo\/amo.php';<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0434\u043e\u043c\u0435\u043d AmoCRM \u0431\u0435\u0440\u0435\u043c \u0438\u0437 url \u043d\u0430\u0448\u0435\u0439 CRM<br \/>\u0412 <em>$redirect_uri<\/em> \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0432\u043e\u0439 \u0434\u043e\u043c\u0435\u043d \u0441\u0430\u0439\u0442\u0430<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0438\u0434\u0435\u043c \u0432 \u0444\u0430\u0439\u043b <em>auth.php<\/em> \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"php\">&lt;?php require_once 'config.php';  $link = \"https:\/\/$subdomain.amocrm.ru\/oauth2\/access_token\";  $data = [   'client_id'     => $client_id,   'client_secret' => $client_secret,   'grant_type'    => 'authorization_code',   'code'          => $code,   'redirect_uri'  => $redirect_uri, ];  $curl = curl_init(); curl_setopt($curl,CURLOPT_RETURNTRANSFER, true); curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-oAuth-client\/1.0'); curl_setopt($curl,CURLOPT_URL, $link); curl_setopt($curl,CURLOPT_HTTPHEADER, ['Content-Type:application\/json']); curl_setopt($curl,CURLOPT_HEADER, false); curl_setopt($curl,CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl,CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, 2); $out = curl_exec($curl); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); $code = (int)$code;  $errors = [ 301 => 'Moved permanently.',   400 => 'Wrong structure of the array of transmitted data, or invalid identifiers of custom fields.',   401 => 'Not Authorized. There is no account information on the server. You need to make a request to another server on the transmitted IP.',   403 => 'The account is blocked, for repeatedly exceeding the number of requests per second.',   404 => 'Not found.',   500 => 'Internal server error.',   502 => 'Bad gateway.',   503 => 'Service unavailable.' ];  if ($code &lt; 200 || $code > 204) die( \"Error $code. \" . (isset($errors[$code]) ? $errors[$code] : 'Undefined error') );   $response = json_decode($out, true);  $arrParamsAmo = [ \"access_token\"  => $response['access_token'], \"refresh_token\" => $response['refresh_token'], \"token_type\"    => $response['token_type'], \"expires_in\"    => $response['expires_in'], \"endTokenTime\"  => $response['expires_in'] + time(), ];  $arrParamsAmo = json_encode($arrParamsAmo);  $f = fopen($token_file, 'w'); fwrite($f, $arrParamsAmo); fclose($f);  print_r($arrParamsAmo);<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 AmoCRM \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u0432. \u0422\u043e\u043a\u0435\u043d\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b <em>(45-57 \u0441\u0442\u0440\u043e\u043a\u0438)<\/em>, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u0445 \u0432 \u0411\u0414.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0444\u0430\u0439\u043b, https:\/\/site.com\/amo\/auth.php<br \/>\u041a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0439\u043b\u0435 tokens.txt \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<h2>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0430<\/h2>\n<p>Access token \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<br \/>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b <em>access.php<\/em> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"php\">&lt;?php require_once 'config.php';  $dataToken = file_get_contents($token_file); $dataToken = json_decode($dataToken, true);  if ($dataToken[\"endTokenTime\"] &lt; time()) {      $link = \"https:\/\/$subdomain.amocrm.ru\/oauth2\/access_token\";      $data = [         'client_id'     => $client_id,         'client_secret' => $client_secret,         'grant_type'    => 'refresh_token',         'refresh_token' => $dataToken[\"refresh_token\"],         'redirect_uri'  => $redirect_uri,     ];      $curl = curl_init();     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);     curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-oAuth-client\/1.0');     curl_setopt($curl, CURLOPT_URL, $link);     curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type:application\/json']);     curl_setopt($curl, CURLOPT_HEADER, false);     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');     curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);     $out = curl_exec($curl);     $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);     curl_close($curl);      $code = (int)$code;     $errors = [         301 => 'Moved permanently.',         400 => 'Wrong structure of the array of transmitted data, or invalid identifiers of custom fields.',         401 => 'Not Authorized. There is no account information on the server. You need to make a request to another server on the transmitted IP.',         403 => 'The account is blocked, for repeatedly exceeding the number of requests per second.',         404 => 'Not found.',         500 => 'Internal server error.',         502 => 'Bad gateway.',         503 => 'Service unavailable.'     ];      if ($code &lt; 200 || $code > 204) die( \"Error $code. \" . (isset($errors[$code]) ? $errors[$code] : 'Undefined error') );      $response = json_decode($out, true);      $arrParamsAmo = [         \"access_token\"  => $response['access_token'],         \"refresh_token\" => $response['refresh_token'],         \"token_type\"    => $response['token_type'],         \"expires_in\"    => $response['expires_in'],         \"endTokenTime\"  => $response['expires_in'] + time(),     ];      $arrParamsAmo = json_encode($arrParamsAmo);      $f = fopen($token_file, 'w');     fwrite($f, $arrParamsAmo);     fclose($f);      $access_token = $response['access_token'];  } else {     $access_token = $dataToken[\"access_token\"]; }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0411\u0414, \u043f\u0440\u043e\u043f\u0438\u0448\u0438\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0445 \u0438\u0437 \u0411\u0414 <em>(59-61 \u0441\u0442\u0440\u043e\u043a\u0438)<\/em>.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 html \u0444\u043e\u0440\u043c\u044b, \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0443 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 <em>amo.php<\/em> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c amo.php \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"php\">&lt;?php  require_once 'access.php';  $name = '\u0418\u043c\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430'; $phone = '+380123456789'; $email = 'email@gmail.com'; $target = '\u0426\u0435\u043b\u044c'; $company = '\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438';  $custom_field_id = 454021; $custom_field_value = '\u0442\u0435\u0441\u0442';  $ip = '1.2.3.4'; $domain = 'site.com'; $price = 0; $pipeline_id = 5059931; $user_amo = 0;  $utm_source   = ''; $utm_content  = ''; $utm_medium   = ''; $utm_campaign = ''; $utm_term     = ''; $utm_referrer = '';  $data = [     [         \"name\" => $phone,         \"price\" => $price,         \"responsible_user_id\" => $user_amo,         \"pipeline_id\" => $pipeline_id,         \"_embedded\" => [             \"metadata\" => [                 \"category\" => \"forms\",                 \"form_id\" => 1,                 \"form_name\" => \"\u0424\u043e\u0440\u043c\u0430 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435\",                 \"form_page\" => $target,                 \"form_sent_at\" => strtotime(date(\"Y-m-d H:i:s\")),                 \"ip\" => $ip,                 \"referer\" => $domain             ],             \"contacts\" => [                 [                     \"first_name\" => $name,                     \"custom_fields_values\" => [                         [                             \"field_code\" => \"EMAIL\",                             \"values\" => [                                 [                                     \"enum_code\" => \"WORK\",                                     \"value\" => $email                                 ]                             ]                         ],                         [                             \"field_code\" => \"PHONE\",                             \"values\" => [                                 [                                     \"enum_code\" => \"WORK\",                                     \"value\" => $phone                                 ]                             ]                         ],                         [                             \"field_id\" => $custom_field_id,                             \"values\" => [                                 [                                     \"value\" => $custom_field_value                                 ]                             ]                         ]                     ]                 ]             ],             \"companies\" => [                 [                     \"name\" => $company                 ]             ]         ],         \"custom_fields_values\" => [             [                 \"field_code\" => 'UTM_SOURCE',                 \"values\" => [                     [                         \"value\" => $utm_source                     ]                 ]             ],             [                 \"field_code\" => 'UTM_CONTENT',                 \"values\" => [                     [                         \"value\" => $utm_content                     ]                 ]             ],             [                 \"field_code\" => 'UTM_MEDIUM',                 \"values\" => [                     [                         \"value\" => $utm_medium                     ]                 ]             ],             [                 \"field_code\" => 'UTM_CAMPAIGN',                 \"values\" => [                     [                         \"value\" => $utm_campaign                     ]                 ]             ],             [                 \"field_code\" => 'UTM_TERM',                 \"values\" => [                     [                         \"value\" => $utm_term                     ]                 ]             ],             [  <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-329162","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/329162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=329162"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/329162\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=329162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=329162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=329162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}