{"id":665,"date":"2024-12-13T16:37:59","date_gmt":"2024-12-13T16:37:59","guid":{"rendered":"https:\/\/faq.cinar-studio.ru\/?p=665"},"modified":"2024-12-13T16:37:59","modified_gmt":"2024-12-13T16:37:59","slug":"sozdanie-lida-amo-crm-mfp-cherez-dolgosrochnyj-token-integracziya-s-cf7","status":"publish","type":"post","link":"https:\/\/faq.cinar-studio.ru\/?p=665","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043b\u0438\u0434\u0430 AMO CRM (\u041c\u0424\u041f) \u0447\u0435\u0440\u0435\u0437 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \/ \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 CF7"},"content":{"rendered":"<p>add_action(&#8216;wpcf7_mail_sent&#8217;, &#8216;send_lead_to_amocrm&#8217;);<\/p>\n<p>function send_lead_to_amocrm($contact_form) {<br \/>\n\/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u043e\u0440\u043c\u044b<br \/>\n$submission = WPCF7_Submission::get_instance();<\/p>\n<p>if ($submission) {<br \/>\n$posted_data = $submission-&gt;get_posted_data();<\/p>\n<p>\/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0432 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<br \/>\n$name = isset($posted_data[&#8216;your-name&#8217;]) ? $posted_data[&#8216;your-name&#8217;] : &#8216;\u0417\u0430\u044f\u0432\u043a\u0430&#8217;;<br \/>\n$phone = isset($posted_data[&#8216;your-phone&#8217;]) ? $posted_data[&#8216;your-phone&#8217;] : &#8221;;<br \/>\nif (empty($phone)) {<br \/>\nreturn;<br \/>\n}<\/p>\n<p>\/\/ \u0412\u0430\u0448 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d<br \/>\n$access_token = &#8216;\u0442\u0432\u043e\u0439 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d&#8217;;<\/p>\n<p>\/\/ \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f AmoCRM<br \/>\n$lead_data = [<br \/>\n[<br \/>\n&#8220;name&#8221; =&gt; &#8220;\u0417\u0430\u044f\u0432\u043a\u0430 \u0441 \u0441\u0430\u0439\u0442\u0430&#8221;,<br \/>\n&#8220;_embedded&#8221; =&gt; [<br \/>\n&#8220;contacts&#8221; =&gt; [<br \/>\n[<br \/>\n&#8220;first_name&#8221; =&gt; $name,<br \/>\n&#8220;custom_fields_values&#8221; =&gt; [<br \/>\n[<br \/>\n&#8220;field_code&#8221; =&gt; &#8220;PHONE&#8221;,<br \/>\n&#8220;values&#8221; =&gt; [<br \/>\n[<br \/>\n&#8220;value&#8221; =&gt; $phone,<br \/>\n&#8220;enum_code&#8221; =&gt; &#8220;WORK&#8221;<br \/>\n]<br \/>\n]<br \/>\n]<br \/>\n]<br \/>\n]<br \/>\n]<br \/>\n]<br \/>\n]<br \/>\n];<\/p>\n<p>try {<br \/>\n$curl = curl_init();<\/p>\n<p>curl_setopt_array($curl, [<br \/>\nCURLOPT_URL =&gt; &#8220;https:\/\/dkrexpert.amocrm.ru\/api\/v4\/leads\/complex&#8221;, \/\/\u0441\u044e\u0434\u0430 \u0441\u0432\u043e\u0439 \u043f\u043e\u0434\u0434\u043e\u043c\u0435\u043d \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u044c \u0432\u043c\u0435\u0441\u0442\u043e dkrexpert.amocrm.ru<br \/>\nCURLOPT_RETURNTRANSFER =&gt; true,<br \/>\nCURLOPT_HTTPHEADER =&gt; [<br \/>\n&#8216;Content-Type: application\/json&#8217;,<br \/>\n&#8216;Authorization: Bearer &#8216; . $access_token,<br \/>\n&#8216;Accept: application\/json&#8217;<br \/>\n],<br \/>\nCURLOPT_CUSTOMREQUEST =&gt; &#8216;POST&#8217;,<br \/>\nCURLOPT_POSTFIELDS =&gt; json_encode($lead_data),<br \/>\nCURLOPT_SSL_VERIFYPEER =&gt; 1,<br \/>\nCURLOPT_SSL_VERIFYHOST =&gt; 2<br \/>\n]);<\/p>\n<p>$response = curl_exec($curl);<br \/>\n$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);<\/p>\n<p>\/\/ \u041b\u043e\u0433\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<br \/>\nerror_log(sprintf(<br \/>\n&#8220;AmoCRM API Response\\nStatus: %d\\nPhone: %s\\nResponse: %s&#8221;,<br \/>\n$http_code,<br \/>\n$phone,<br \/>\n$response<br \/>\n));<\/p>\n<p>} catch (Exception $e) {<br \/>\nerror_log(&#8220;AmoCRM API Error: &#8221; . $e-&gt;getMessage());<br \/>\n} finally {<br \/>\nif (isset($curl)) {<br \/>\ncurl_close($curl);<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>add_action(&#8216;wpcf7_mail_sent&#8217;, &#8216;send_lead_to_amocrm&#8217;); function send_lead_to_amocrm($contact_form) { \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u043e\u0440\u043c\u044b $submission = WPCF7_Submission::get_instance(); if ($submission) { $posted_data = $submission-&gt;get_posted_data(); \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0432 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 $name = isset($posted_data[&#8216;your-name&#8217;]) ? $posted_data[&#8216;your-name&#8217;] : &#8216;\u0417\u0430\u044f\u0432\u043a\u0430&#8217;; $phone = isset($posted_data[&#8216;your-phone&#8217;]) ? $posted_data[&#8216;your-phone&#8217;] : &#8221;; if (empty($phone)) { return; } \/\/ \u0412\u0430\u0448 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d $access_token = &#8216;\u0442\u0432\u043e\u0439 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d&#8217;; \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/faq.cinar-studio.ru\/index.php?rest_route=\/wp\/v2\/posts\/665"}],"collection":[{"href":"https:\/\/faq.cinar-studio.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/faq.cinar-studio.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/faq.cinar-studio.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/faq.cinar-studio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=665"}],"version-history":[{"count":2,"href":"https:\/\/faq.cinar-studio.ru\/index.php?rest_route=\/wp\/v2\/posts\/665\/revisions"}],"predecessor-version":[{"id":667,"href":"https:\/\/faq.cinar-studio.ru\/index.php?rest_route=\/wp\/v2\/posts\/665\/revisions\/667"}],"wp:attachment":[{"href":"https:\/\/faq.cinar-studio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/faq.cinar-studio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/faq.cinar-studio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}