Skip to content

Automatic creation of deals from website requests

For deals in the CRM to be created automatically from website requests, you need to set up sending deals to R7K12. We have a ready-made solution for this: deal proxying. You need to set up proxying in the file that processes the forms on your website, for example, the one that sends order data by email. Add this PHP code for each order (request) form, inserting your own variables for the fields:

//Отправка данных в R7K12CRM
$KEY = 'PROJECT KEY';//ключ проекта
$phone = !empty($_REQUEST['phone']) ? $_REQUEST['phone'] : '';
$products = [
    [
        "id" => "1", //код товара (из каталога CRM)
        "name" => "тестовый товар", //название товара
        "price" => "20", //цена товара 1
        "quantity" => "1", //количество
    ]
];
if (preg_match("/^0/",$phone)) $phone = '+38'.$phone;
$CRM = [
    "r7k12id" => isset($_COOKIE['r7k12_si']) ? $_COOKIE['r7k12_si'] : null,
    "type" => "Form",//Тип заявки (ОБЯЗАТЕЛЬНО)
    "title" => $_REQUEST['title'],//Заголовок заявки (НЕ ОБЯЗАТЕЛЬНО)
    "href" => $_SERVER['HTTP_REFERER'],//Ссылка на страницу, с которой пришла заявка (НЕ ОБЯЗАТЕЛЬНО)
    "comment" => $_REQUEST['comment'],//Комментарий к сделке (НЕ ОБЯЗАТЕЛЬНО)
    "name" => $_REQUEST['name'],//Название контакта (НЕ ОБЯЗАТЕЛЬНО)
    "email" => $_REQUEST['email'],//E-mail адрес контакта (ОБЯЗАТЕЛЕН ЕСЛИ НЕ УКАЗАН ТЕЛЕФОН КОНТАКТА)
    "phone" => $phone,//Телефон контакта (ОБЯЗАТЕЛЕН ЕСЛИ НЕ УКАЗАН E-MAIL КОНТАКТА)
    "shop" => $products[0]['name'],//Магазин
    "department" => 1,//ID Отдела из R7K12 CRM
    "create_new_lead" => "1", //'0' - новая сделка создается только если нет сделки или предыдущая в статусе "успешно реализовано" или "возврат"; '1' - новая сделка создается в любом случае (НЕ ОБЯЗАТЕЛЬНО)
    "fields" => [
        "lead" => [//Поля для сделок
            "products" => $products,
            "revenue" => array_sum(array_map(function($p){return $p['price'] * $p['quantity'];}, $products)),
        ],
        "contact" => [//Поля для контактов
        ],
    ],
];
$context = stream_context_create([
    "http" => [
        "method" => "POST",
        "content" => json_encode($CRM),
    ],
]);

file_get_contents("https://r7k12.com/" . $KEY . "/crm/", false, $context);
//Завершение отправки данных в R7K12CRM

Parameters:

Parameter Type Required Description
r7k12id string no visit ID
type string yes request type
title string no request name
href string no link to the page the request was sent from
comment string no comment
name string no client name
email string yes (if phone is not specified) client email
phone string yes (if email is not specified) client phone number
create_new_lead boolean no value '0' - a new deal is created only if there is no deal or the previous one is in the “Completed” or “Canceled” status '1' - a new deal is created in any case create a new deal in any case
fields object no custom deal and contact fields
fields[lead] object no custom deal fields
fields[lead][products] object no products in the deal
fields[lead][products][][id] string yes product ID
fields[lead][products][][name] string no product name
fields[lead][products][][price] float no product price
fields[lead][products][][quantity] integer yes quantity

With this code, you can set up sending data from website requests to R7K12 CRM, and the service will automatically create deals from them in your CRM. We explain the parts of the code in more detail below. 1. In your project's Settings, copy the Project key. Example: In the first line of the code, $KEY = 'PROJECT KEY';, paste your key from the settings. Example:

$KEY = '3f797313ca7ac12686167fdda5eae839'; //ключ проекта
  1. In the $products array, you can pass the following product data: code, name, price, quantity. Example of sending two kinds of products in the array:
$products = [
    [
    "id" => "1",//код товара (из каталога CRM)
        "name" => "Товар 1",
        "price" => 10, //цена товара 1
        "quantity" => 3
  ],
  [
        "id" => '2',    //код товара (из каталога CRM)
        "name" => 'Товар 2',
        "price" => 20, //цена товара 2
        "quantity" => 1
    ]
];

If you send an order with a product that is not yet in the CRM warehouse, the product will be added to the R7K12 CRM warehouse automatically.

  1. In the $CRM array, you need to specify the data and variables for sending information about the request and the contact. In the line
'type' => $type,

the request type is specified. You can set up sending with the 'Form' type for all forms on the website. Or give each form or group of forms its own type name. This way, in analytics you will be able to see which forms people submit requests from most often. In the line

"href" => $_SERVER['HTTP_REFERER'],

the page from which the request was submitted will be read automatically. But it is better to set the page where the form is located statically for each form ('href' => 'http://site.com'). Next, for the 'comment', 'name', 'name', 'phone' fields, specify the corresponding variables from your forms. The line

'create_new_lead' => '1'

controls the algorithm for creating a deal from form inquiries. Value '0' - a new deal is created only if there is no deal or the previous one is in the “Completed” or “Canceled” status. Value '1' - a new deal is created in any case. The 'fields' array passes the products. You can also specify additional fields for the deal and contact here.