How to Test Your Handler for Bitrix24 Event Processing
If you are developing integrations for Bitrix24 using AI tools (Codex, Claude Code, Cursor), connect to the MCP server so that the assistant can utilize the official REST documentation.
After registering the handler ONAPPTEST, the method event.test is called manually. This triggers the specified event and allows you to verify that the handler is indeed capable of receiving event data.
Step 1
Create a file named handler.php on your server. Ensure it is accessible from the internet. Next to the file, create a folder named \log.
Code for the file handler.php.
How to Use Examples in Documentation
<?php
file_put_contents(
__DIR__ . '/log/' . time() . '.txt',
var_export($_REQUEST, true)
);
?>
Step 2
Register the event by specifying the path to the file created in Step 1 in the handler field.
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"event":"ONAPPTEST","handler":"https://example.com/handler.php","auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/event.bind
// This snippet is an ES module: top-level await requires type="module" or a bundler.
// $b24 is an already-initialized SDK instance (see the SDK "Get started" guide).
import { Text } from '@bitrix24/b24jssdk'
import type { B24Frame } from '@bitrix24/b24jssdk'
declare const $b24: B24Frame
try {
const response = await $b24.actions.v2.call.make<boolean>({
method: 'event.bind',
params: {
event: 'ONAPPTEST',
handler: 'https://example.com/handler.php',
},
requestId: Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
} else {
const result = response.getData()!.result
console.info('event.bind result:', result)
}
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
<!-- Load the SDK (UMD build); it is exposed as the global B24Js -->
<script src="https://unpkg.com/@bitrix24/b24jssdk@1/dist/umd/index.min.js"></script>
<script>
async function bindEvent() {
try {
// Initialize the SDK inside a Bitrix24 frame
const $b24 = await B24Js.initializeB24Frame()
const response = await $b24.actions.v2.call.make({
method: 'event.bind',
params: {
event: 'ONAPPTEST',
handler: 'https://example.com/handler.php',
},
requestId: B24Js.Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
return
}
const result = response.getData().result
console.info('event.bind result:', result)
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
}
document.addEventListener('DOMContentLoaded', bindEvent)
</script>
<?php
$eventBind = CRest::call(
'event.bind',
[
'event' => 'ONAPPTEST',
'handler' => 'https://example.com/handler.php'
]
);
if($eventBind['result'])
{
echo 'event bind successful';
}
?>
Step 3
Trigger the event by calling the method with arbitrary data.
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"any":"data","auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/event.test
// This snippet is an ES module: top-level await requires type="module" or a bundler.
// $b24 is an already-initialized SDK instance (see the SDK "Get started" guide).
import { Text } from '@bitrix24/b24jssdk'
import type { B24Frame } from '@bitrix24/b24jssdk'
declare const $b24: B24Frame
try {
const response = await $b24.actions.v2.call.make<boolean>({
method: 'event.test',
params: {
any: 'data',
},
requestId: Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
} else {
const result = response.getData()!.result
console.info('event.test result:', result)
}
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
<!-- Load the SDK (UMD build); it is exposed as the global B24Js -->
<script src="https://unpkg.com/@bitrix24/b24jssdk@1/dist/umd/index.min.js"></script>
<script>
async function testEvent() {
try {
// Initialize the SDK inside a Bitrix24 frame
const $b24 = await B24Js.initializeB24Frame()
const response = await $b24.actions.v2.call.make({
method: 'event.test',
params: {
any: 'data',
},
requestId: B24Js.Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
return
}
const result = response.getData().result
console.info('event.test result:', result)
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
}
document.addEventListener('DOMContentLoaded', testEvent)
</script>
<?php
$result = CRest::call(
'event.test',
[
'any' => 'data'
]
);
if($result['result'])
{
echo 'successful';
}
?>
Result
Upon a successful call, a file with standard event data is created in the \log folder.
array (
'event' => 'ONAPPTEST',
'data' =>
array (
'QUERY' =>
array (
'any' => 'data',
),
'LANGUAGE_ID' => 'en',
),
'ts' => '1573120286',
'auth' => array (...)
)