1. Home
  2. Docs
  3. Для администраторов
  4. How to connect the site for incoming requests?

How to connect the site for incoming requests?

Generate token
Go to Settings -> Sites

 

Click on the «Add» button and enter the address of your site in the «Domain» field (for example best.com)

 

 

Click the «Save» button at the bottom of the page.

 

 

After saving, you will see the generated code in the «Token»

 

 

 

Copy this code, it will be needed later.

PHP

You must have the php-curl module installed. Copy the code below to your php page. Do not forget to change {{YOUR TOKEN}} to the generated code, and {{YOUR ERP ADDRESS}} to your ERP address (eg best.diga.pt)

$name = $_POST[‘name’];
$email = $_POST[’email’];
$phone = $_POST[‘phone’];
$message = $_POST[‘message’];

addToERP($name, $phone, $email, $message);

function addToERP($name, $phone, $email, $message){

$post_data = array(
‘token’ => ‘{{YOUR TOKEN}}’,
‘type’ => ‘new_client’,
‘name’ => $name,
‘phone’ => $phone,
’email’ => $email,
‘message’ => $message
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, ‘https://{{ YOUR ERP ADDRESS }}/api’);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);
}

JavaScript

You must have a jQuery library

$.post(‘https://{{ YOUR ERP ADDRESS }}/api’, {
token: ‘{{YOUR TOKEN}}’,
type: ‘new_client’,
name: name,
phone: phone,
email: email,
message: message
}, function() {
alert(‘Request sent’);
});

For more information about the API, see API Reference

Was this article helpful to you? Yes No