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
- 09.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
- 07.07.22IT / Safety How to protect PHP, JS, HTML, CSS source code - obfuscation, minification, compression and encryption
- 06.07.22IT / Safety Connection not secure, problem with Lets Encrypt - how to fix expired 09/30/2021 DST Root CA X3, remove it manually and install ISRG Root X1. Example on MS Windows 7
- 08.07.21IT / Misc How to make a free translation for a website without an API, translate documents in Google Translate
- 06.07.21IT / Misc How to make a subscription button on a website, a subscriber base and automatic mailing