Сборка материалов по bx24

Curl для rest api

Открыть

        
function doCurl($method = '', $query = array())
{

    $bx24_url = 'url';
    $bx24_user_id = (int);
    $bx24_key = 'webhook_key';

    $queryUrl = 'https://'.$bx24_url.'/rest/'.$bx24_user_id.'/'.$bx24_key.'/' . $method;
    $c = curl_init($queryUrl); //?select[0]=UF_*
    $queryData = http_build_query($query);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($c, CURLOPT_POST, true);
    curl_setopt($c, CURLOPT_HEADER, false);
    curl_setopt($c, CURLOPT_POSTFIELDS, $queryData);
    $response = curl_exec($c);
    $response = json_decode($response, true);

    return $response;
}

$c = doCurl('crm.contact.list.json', array( 
            'select' => array("ID", "TITLE", "PHONE")
        ));
print_r($c['result']);
        
    

WP CF7 - создание сделки и контакта с проверкой в bx24 после отправки формы

Открыть

        
/*
 * Отправка контакта и сделки в bx24 после отправки формы
 */
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_start_function' );
function wpcf7_before_send_mail_start_function($cf7){

    $mail=$cf7->prop('mail');
    if($mail){

        $submission = WPCF7_Submission::get_instance();
        $data = $submission->get_posted_data();


        $name = $data['your-name'];
        $phone = $data['tel-488'];

        /*
         * получаем все контакты и
         * проверяем наличие телефона во всех контактах
         */
        $contacts = doCurl('crm.contact.list.json', array( //?select=UF_*
            'select' => array("ID", "TITLE", "PHONE")
        ));
        $contacts_phones = [];
        foreach ($contacts['result'] as $element_phone) {
            $contacts_phones['phones']['id'][] = $element_phone['PHONE'][0]['ID'];
            $contacts_phones['phones']['value'][] = $element_phone['PHONE'][0]['VALUE'];
        }
        /*
         * получаем id контакта если он есть
         */
        foreach ($contacts['result'] as $element_phone) {
            if(is_array($element_phone['PHONE'])){
                foreach ($element_phone['PHONE'] as $item) {
                    if ($item['VALUE'] === $phone) {
                        $contact_id = $element_phone['ID'];
                    }
                }

            }
        }
        /*
         * если нет контакта -  создаем
         */
        if (!in_array($phone, $contacts_phones['phones']['value'])) {

            $add_contact = doCurl('crm.contact.add.json', array(
                'fields' => array(
                    "NAME" => $name,
                    "PHONE" => array(
                        [
                            "ID" => '',
                            "VALUE" => $phone,
                            "VALUE_TYPE" => "WORK",
                            "TYPE_ID" => 'PHONE'
                        ]
                    ),
                ),

                'params' => array(
                    "REGISTER_SONET_EVENT" => "Y"
                )
            ));

            $contact_id = $add_contact['result'];
        }


        $create_deal = doCurl('crm.deal.add.json', array( //?select=UF_*
            'fields' => array(
                'TITLE' => $mail['subject'],
                "STAGE_ID" => "NEW",
                "CONTACT_ID" => $contact_id,
                "OPENED" => "Y",
               // 'COMMENTS' =>  '' ,
            ),
            'params' => array(
                "REGISTER_SONET_EVENT" => "Y"
            )
        ));
    }//if($mail)
}
        
    
Тэги:

Комментарии (0)


Оставить комментарий

Success/Error Message Goes Here

TOP