# @bitrix/crest [English](#contenten) | [Русский](#contentru)
@bitrix/crest — small PHPSDK used for Bitrix24 REST API for webhooks, local or public applications. # Contents 1. [Description](#description) 2. [Calling using inbound webhook](#usingwebhook) 3. [Calling from local application](#localapp) 4. [Calling from public application](#publicapp) ##
Description ```php define('C_REST_CURRENT_ENCODING','windows-1251'); ``` ##
Calling REST using inbound webhook Indicate webhook URL in define C_REST_WEB_HOOK_URL inside the settings.php file: ```php define('C_REST_WEB_HOOK_URL','https://xxx.bitrix24.ru/rest/1/douasdqdsxSWgc3mgc1/'); ``` Insert example text into the index.php file: ```php require_once('src/crest.php'); // put an example below echo '
';
print_r(CRest::call(
   'crm.lead.add',
   [
      'fields' =>[
          'TITLE' => 'Lead name',//Title*[string]
          'NAME' => 'Name',//Name[string]
          'LAST_NAME' => 'Last name',//Last name[string]
      ]
   ])
);

echo '
'; ``` Indicate example URL in the browser address bar https://example.com/index.php to see the example results. ##
Calling REST from local application Insert example text into the index.php file: ```php require_once('src/crest.php'); // put an example below echo '
';
print_r(CRest::call(
   'crm.lead.add',
   [
      'fields' =>[
          'TITLE' => 'Lead name',//Title*[string]
          'NAME' => 'Name',//Name[string]
          'LAST_NAME' => 'Last name',//Last name[string]
      ]
   ])
);

echo '
'; ``` Indicate your app URL https://example.com/index.php as well as installation script URL https://example.com/install.php inside the local app details form. Indicate parameters client_id and client_secret for OAuth 2.0 authorization in define C_REST_CLIENT_ID and C_REST_CLIENT_SECRET inside the settings.php file. Take these values from the local app details form.
In the list of local applications, click on your local app and select “Reinstall”. It’s required for install.php to operate correctly after you have indicated correct values C_REST_CLIENT_ID and C_REST_CLIENT_SECRET. After installation is complete, you will see example results. When the example demonstrates widget embedding into other Bitrix24 tools, switch to these tools. ##
Calling REST from public application Insert example text into the index.php file: ```php require_once('src/crest.php'); // put an example below echo '
';
print_r(CRest::call(
   'crm.lead.add',
   [
      'fields' =>[
          'TITLE' => 'Lead name',//Title*[string]
          'NAME' => 'Name',//Name[string]
          'LAST_NAME' => 'Last name',//Last name[string]
      ]
   ])
);

echo '
'; ``` Add a public application inside the partner’s account to get client_id and client_secret as well as when saving an application. Indicate parameters client_id and client_secret OAuth 2.0 authorization in define C_REST_CLIENT_ID and C_REST_CLIENT_SECRET in the settings.php file. Select and indicate your application URL https://example.com/index.php and installation script URL https://example.com/install.php inside the app details form. After saving the version, open the version details and install your app to any available Bitrix24 by clicking on "Install". After installation is complete, you will see example results (when the example demonstrates widget embedding into other Bitrix24 tools, switch to these tools). For actual public app operation, you must inherit CRest class by redefining methods getSettingData/setSettingData that get/save authentication tokens in text file. These methods are not designed for application working on several Bitrix24 simultaneously.




@bitrix/crest — небольшой PHPSDK для использования REST API Битрикс24 в локальных, тиражных приложениях или через вебхуки # Содержание 1. [Описание](#introduction) 2. [Вызов при помощи входящего вебхука](#webhook) 3. [Вызов из локального приложения](#local) 4. [Вызов из тиражного приложения](#public) ##
Описание ```php define('C_REST_CURRENT_ENCODING','windows-1251'); ``` ##
Вызов REST с использованием входящего вебхука Укажите URL вебхука в define C_REST_WEB_HOOK_URL в файле settings.php: ```php define('C_REST_WEB_HOOK_URL','https://xxx.bitrix24.ru/rest/1/douasdqdsxSWgc3mgc1/'); ``` Вставьте текст примера в файл index.php: ```php require_once('src/crest.php'); // put an example below echo '
';
print_r(CRest::call(
   'crm.lead.add',
   [
      'fields' =>[
          'TITLE' => 'Название лида',//Заголовок*[string]
          'NAME' => 'Имя',//Имя[string]
          'LAST_NAME' => 'Фамилия',//Фамилия[string]
      ]
   ])
);

echo '
'; ``` Укажите URL к примеру в адресной строке браузера https://example.com/index.php, чтобы увидеть результат работы примера. ##
Вызов REST из локального приложения Вставьте текст примера в файл index.php: ```php require_once('src/crest.php'); // put an example below echo '
';
print_r(CRest::call(
   'crm.lead.add',
   [
      'fields' =>[
          'TITLE' => 'Название лида',//Заголовок*[string]
          'NAME' => 'Имя',//Имя[string]
          'LAST_NAME' => 'Фамилия',//Фамилия[string]
      ]
   ])
);

echo '
'; ``` В карточке локального приложения укажите URL своего приложения https://example.com/index.php и URL скрипта установки https://example.com/install.php. Укажите значения параметров client_id и client_secret для авторизации OAuth 2.0 в define C_REST_CLIENT_ID и C_REST_CLIENT_SECRET в файле settings.php, взяв эти значения из карточки локального приложения.
В списке локальных приложений нажмите правой кнопкой мыши на своё локальное приложение и выберите пункт "Переустановить". Это нужно чтобы корректно сработал install.php после того, как вы вставили корректные значения C_REST_CLIENT_ID и C_REST_CLIENT_SECRET. После установки вы увидите результат работы примера. Если пример демонстрирует встраивание виджетов в другие инструменты Битрикс24, необходимо перейти в эти инструменты. ##
Вызов REST из тиражного приложения Вставьте текст примера в файл index.php ```php require_once('src/crest.php'); // put an example below echo '
';
print_r(CRest::call(
   'crm.lead.add',
   [
      'fields' =>[
          'TITLE' => 'Название лида',//Заголовок*[string]
          'NAME' => 'Имя',//Имя[string]
          'LAST_NAME' => 'Фамилия',//Фамилия[string]
      ]
   ])
);

echo '
'; ``` Добавьте тиражное приложение в партнерском кабинете для получения client_id и client_secret и при сохранении приложения. Укажите значения параметров client_id и client_secret для авторизации OAuth 2.0 в define C_REST_CLIENT_ID и C_REST_CLIENT_SECRET в файле settings.php.
В карточке приложения добавьте версию и укажите URL своего приложения https://example.com/index.php и URL скрипта установки https://example.com/install.php в карточке версии. После сохранения версии откройте карточку версии и, нажав на ссылку "Установить на своем Битрикс24", установите свое приложение на любой доступный вам Битрикс24. После установки вы увидите результат работы примера (в случае, если пример демонстрирует встраивание виджетов в другие инструменты Битрикс24, необходимо перейти в эти инструменты). Для реального тиражного приложения необходимо пронаследовать класс CRest, переопределив методы getSettingData/setSettingData, которые занимается получением/сохранением токенов авторизации в текстовый файл. Эти методы не предназначены для эксплуатации приложения на нескольких Битрикс24 одновременно.