Answer the question
In order to leave comments, you need to log in
How to create a webhook for your custom handler in Bitrix24?
I have a boxed version of the Bitrix24 portal. I need to implement a search by Bitrix24 infoblock elements (lists) so that I can send a webhook request with parameters from a third-party site to my Bitrix24 and get the required list of elements from Bitrix24 infoblocks. The problem is that in the standard REST API there is no way to search by the fields or properties of the infoblock elements, and through the standard REST FILTER the result is returned
incorrectly. through the Bitrix API and then return the result as json.
Next, I want to make a webhook that will be attached to this handler.
But I don't know how to make such a webhook correctly, help me figure it out!
There is an instruction on how to make a custom REST handler
. I made a handler according to this instruction and attached a webhook to it, but the webhook returns the following message: {"error":"ERROR_METHOD_NOT_FOUND","error_description":"Method not found!"}
Here is the handler code:
public static function OnRestServiceBuildDescription()
{
return array(
'apitest' => array(
'api.test.list' => array(
'callback' => array(__CLASS__, 'getList'),
'options' => array(),
),
)
);
}
public static function getList($query, $nav, \CRestServer $server)
{
$navData = static::getNavData($nav, true);
$res = \Bitrix\Main\UserTable::getList(
[
'filter' => $query['filter']?:[],
'select' => $query['select']?:['*'],
'order' => $query['order']?:['ID' => 'ASC'],
'limit' => $navData['limit'],
'offset' => $navData['offset'],
'count_total' => true,
]
);
$result = array();
while($user = $res->fetch())
{
$result[] = $user;
}
return static::setNavData(
$result,
array(
"count" => $res->getCount(),
"offset" => $navData['offset']
)
);
}
}
AddEventHandler('rest', 'OnRestServiceBuildDescription', array('\ApiTest', 'OnRestServiceBuildDescription'));
Answer the question
In order to leave comments, you need to log in
Don't know. It works like this for me: https://gist.github.com/BedrosovaYulia/0aa8800b704...
just try to write a simpler example first, so that it stupidly returns some constant, then screw it up. And you did not forget to connect the file with your class in the Internet?
It is ideal to make a module and register the handler once during installation
EventManager::getInstance()->registerEventHandler(
'rest',
'OnRestServiceBuildDescription',
$this->MODULE_ID,
'ApiTest',
'OnRestServiceBuildDescription'
);
AddEventHandler(
'rest',
'OnRestServiceBuildDescription',
['ApiTest', 'OnRestServiceBuildDescription'],
false,
$_SERVER['DOCUMENT_ROOT'] . '/habr/ApiTest.php'
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question