API
Table of contents
TheAPI provides opportunities for programmatic interaction with the system from different places, for example, from its own entities (modules, themes, etc.), as well as access from external resources. All functionality is distributed over certain sections of the system and is divided into two types of API:
- Internal (internal) - available only inside the system, including access from custom entities (modules, themes, etc.);
- External (external) - accessible from anywhere, including access from third-party resources.
It is recommended that all provided API methods be set explicitly, for which their description in service files is required in the form:
class Service {
// ...
public $api = [
'get_user_id' => [
'type' => 'internal', // external or internal if not specified - internal
'access' => ['administrator',], // access only for the specified user roles, if not specified - access for everyone
'format' => 'json_object', // json or json_object if not specified - data will be returned as normal
'method' => 'get_user_id_plus', // method to override, if not specified, the original one will be called
],
];
function get_api() {
return $this->api;
}
// ...
}
External API methods must be called at the address of the form https://example.com/api, to which you want to send data using the POST or GET:
- key - API key, usually 12345. The key for comparison is set in the settings (file settings.php - api_key);
- module - called module;
- method - the method to be called in the specified module;
- data - other miscellaneous data (optional).
API access authorization may be needed in some scenarios - for example, if an API method has an array of roles with access. The following authorization mechanisms can be used for this (authorization data is sent along with the rest of the data using the POST or GET method):
- an authorization token can be sent - token parameter, the system will automatically authorize the user. Such a token can be obtained during authorization using various applications or interfaces that request a username and password;
- it is possible to restore an authorized session by sending a session identifier - the session name is set in the system settings (file settings.php - session_name), for example, EQSASH_SESSION.
Latest articles
- 03.04.24IT / Уроки PHP Уроки простыми словами. Урок 3. Все операторы PHP с примерами, с выводом работы кода на экран.
- 02.04.24IT / Уроки PHP Уроки простыми словами. Урок 2. Типы данных в PHP с примерами.
- 02.04.24IT / Уроки PHP Уроки простыми словами. Урок 1. Коротко о языке веб-программирования PHP. Основы синтаксиса.
- 09.11.23IT / Database Errors when migrating from MySQL 5.6 to 5.7 and how to fix them - database dump import failed with an error or INSERT does not work. Disabling STRICT_TRANS_TABLES strict mode or using IGNORE
- 08.07.22IT / Misc Convert office files DOC, DOCX, DOCM, RTF to DOCX, DOCM, DOC, RTF, PDF, HTML, XML, TXT formats without loss and markup changes