├── .idea
├── crest.iml
├── misc.xml
├── modules.xml
└── vcs.xml
├── LICENSE
├── README.md
└── src
├── checkserver.php
├── crest.php
├── index.php
├── install.php
└── settings.php
/.idea/crest.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Bitrix
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # @bitrix/crest
2 | [English](#contenten) | [Русский](#contentru)
3 |
4 |
5 |
6 | @bitrix/crest — small PHPSDK used for Bitrix24 REST API for webhooks, local or public applications.
7 |
8 | # Contents
9 | 1. [Description](#description)
10 | 2. [Calling using inbound webhook](#usingwebhook)
11 | 3. [Calling from local application](#localapp)
12 | 4. [Calling from public application](#publicapp)
13 |
14 |
15 | ## Description
16 |
17 |
18 |
Provided examples use cURL module to run REST requests. You need to learn how to enable cURL module on your server.
19 |
Your web server must have valid SSL certificate.
20 |
Examples use base SDK as CRest class for running requests and extending authentication tokens. Download files from repository and implement necessary authorization updates in settings.php file and place it on your server, inserting an example you need from documentation.
21 |
When SDK errors occur, you can open file checkserver.php in browser; it performs minimum server settings check to enable CRest class operation.
22 |
When project uses CRest class and encoding is not UTF-8, there are 2 additional actions:
23 |
Open files from archive and update the encoding to the required one.
24 | Declare the constant C_REST_CURRENT_ENCODING in the settings.php file. For example, when project has encoding windows-1251, the constant must look as follows:
25 |
26 | ```php
27 | define('C_REST_CURRENT_ENCODING','windows-1251');
28 | ```
29 |
30 | ## Calling REST using inbound webhook
31 |
32 | Indicate webhook URL in define C_REST_WEB_HOOK_URL inside the settings.php file:
33 |
34 | ```php
35 | define('C_REST_WEB_HOOK_URL','https://xxx.bitrix24.ru/rest/1/douasdqdsxSWgc3mgc1/');
36 | ```
37 |
38 | Insert example text into the index.php file:
39 |
40 | ```php
41 | require_once('src/crest.php');
42 |
43 | // put an example below
44 | echo '
';
57 | ```
58 |
59 | Indicate example URL in the browser address bar https://example.com/index.php to see the example results.
60 |
61 |
62 | ## Calling REST from local application
63 |
64 | Insert example text into the index.php file:
65 |
66 | ```php
67 | require_once('src/crest.php');
68 |
69 | // put an example below
70 | echo '
';
83 | ```
84 |
85 | 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.
86 | 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.
87 | Take these values from the local app details form.
88 |
89 | 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.
90 | After installation is complete, you will see example results. When the example demonstrates widget embedding into other Bitrix24 tools, switch to these tools.
91 |
92 | ## Calling REST from public application
93 |
94 | Insert example text into the index.php file:
95 |
96 | ```php
97 | require_once('src/crest.php');
98 |
99 | // put an example below
100 | echo '
';
113 | ```
114 |
115 | 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.
116 | 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.
117 |
118 |
119 |
120 |
121 |
122 |
123 | @bitrix/crest — небольшой PHPSDK для использования REST API Битрикс24 в локальных,
124 | тиражных приложениях или через вебхуки
125 |
126 | # Содержание
127 | 1. [Описание](#introduction)
128 | 2. [Вызов при помощи входящего вебхука](#webhook)
129 | 3. [Вызов из локального приложения](#local)
130 | 4. [Вызов из тиражного приложения](#public)
131 |
132 |
133 | ## Описание
134 |
135 |
136 |
Примеры используют модуль cURL для выполнения REST-запросов. Узнайте, как включить модуль cURL на своем сервере.
137 |
На вашем веб-сервере должен быть установлен валидный SSL-сертификат.
138 |
Примеры используют базовый SDK в виде класса CRest для выполнения запросов и продления токенов авторизации. Скачайте файлы из репозитория внесите необходимые правки, связанные с авторизацией в файл settings.php и разместите на своем сервере, вставив нужный вам пример из документации.
139 |
При возникновении проблем с работой SDK вы можете открыть через браузер файл checkserver.php, который произведёт минимальную проверку настроек сервера для работы класса CRest.
140 |
Если в проекте используется класс CRest и кодировка отличается от utf8, то необходимо сделать 2 дополнительных действия:
141 |
Открыть файлы из архива и изменить их кодировку на необходимую.
142 | В файле settings.php объявить константу C_REST_CURRENT_ENCODING. Например, если проект в кодировке windows-1251 константа выглядеть должна так:
143 |
144 | ```php
145 | define('C_REST_CURRENT_ENCODING','windows-1251');
146 | ```
147 |
148 | ## Вызов REST с использованием входящего вебхука
149 |
150 | Укажите URL вебхука в define C_REST_WEB_HOOK_URL в файле settings.php:
151 |
152 | ```php
153 | define('C_REST_WEB_HOOK_URL','https://xxx.bitrix24.ru/rest/1/douasdqdsxSWgc3mgc1/');
154 | ```
155 |
156 | Вставьте текст примера в файл index.php:
157 |
158 | ```php
159 | require_once('src/crest.php');
160 |
161 | // put an example below
162 | echo '
';
201 | ```
202 |
203 | В карточке локального приложения укажите URL своего приложения https://example.com/index.php и URL скрипта установки https://example.com/install.php.
204 | Укажите значения параметров client_id и client_secret для авторизации OAuth 2.0 в define C_REST_CLIENT_ID и C_REST_CLIENT_SECRET в файле settings.php, взяв эти значения из карточки локального приложения.
205 |
206 | В списке локальных приложений нажмите правой кнопкой мыши на своё локальное приложение и выберите пункт "Переустановить". Это нужно чтобы корректно сработал install.php после того, как вы вставили корректные значения C_REST_CLIENT_ID и C_REST_CLIENT_SECRET.
207 | После установки вы увидите результат работы примера. Если пример демонстрирует встраивание виджетов в другие инструменты Битрикс24, необходимо перейти в эти инструменты.
208 |
209 |
210 | ## Вызов REST из тиражного приложения
211 |
212 | Вставьте текст примера в файл index.php
213 |
214 | ```php
215 | require_once('src/crest.php');
216 |
217 | // put an example below
218 | echo '