bitrix24 / b24phpsdk

Bitrix24 PHP SDK for REST API
MIT License
15 stars 4 forks source link

Add support for custom scope for private installations bitrix24 #16

Open mesilov opened 1 month ago

mesilov commented 1 month ago

Todo

Description

When creating your own applications for boxed editions, there is a need to add new methods for them to the REST API. Procedure:

  1. The OnRestServiceBuildDescription event handler of the rest module is registered.
    
    return array(
    'имя_scope' => array(
        'method_name' => array(
            'callback' => method_handler,
            'options' => array(),
        ),
        'method_name' => array(
            'callback' => method_handler,
            'options' => array(),
        ),
    )
    );
3. The scope name is arbitrary. If you register your own scope, it will be available in the list of permissions for local applications. To add methods to an existing scope, specify the method name. If you add methods that are available to all applications, specify the constant \CRestUtil::GLOBAL_SCOPE instead of the name.

The method name is also arbitrary, both upper and lower case are allowed. But it is recommended to stick to the lower case. The traditional naming is scope_name.entity_name.action.

 ```php
 http://cp.sigurd.bx/rest/sigurdtest.test?auth=qcdfzzjtp8hvcbjl42eg93wuw5n0mvsb&test=222
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
    "result": {
        "myresponse": "My own response",  
        "yourquery": {
            "test": "222"
        }
    }
}
http://cp.sigurd.bx/rest/sigurdtest.test.xml?auth=qcdfzzjtp8hvcbjl42eg93wuw5n0mvsb&error=1
HTTP/1.1 402 Payment Required
Content-Type: text/xml; charset=utf-8
<?xml version="1.0" ?>
<response>
    <error>ERROR_CODE</error>
    <error_description>Message</error_description>
</response>

Example