Activate the crm.automation.trigger

Scope: crm

Who can execute the method: a user with access permission to modify the target object target

Bitrix24 allows users to create a special custom trigger "Track Incoming Webhook." The user is provided with a ready-made URL of the form

https://mydomain.bitrix24.com/rest/1/{{PASSWORD}}/crm.automation.trigger/?target=DEAL_{{ID}}&code=nwly5
        

A call to this URL from an external source will trigger the automation and transition the CRM entity to another stage in the Sales Funnel.

As you can see from the format of this URL, a local incoming webhook is effectively created within Bitrix24, which calls the crm.automation.trigger method, specifying a specific CRM object and the unique symbolic code of the trigger that was created by Bitrix24 itself (in the example above, this is nwly5).

You can use the method not only via the incoming webhook but also in the context of local and mass-market applications. However, to invoke your own triggers created by your application, you need to use the method crm.automation.trigger.execute

Method Parameters

Required parameters are marked with *

Name
type

Description

target*
string

Target object for automation, specified in the form of TYPENAME_ID (for example, LEAD_25)

code
string

Unique symbolic code of the trigger configured in Automation for a specific status/stage of the document. The code parameter can be obtained from the trigger settings

Note

In rare cases, multiple triggers may be detected for the specified target object. This happens if:

  • code is not passed in the request and there are old triggers on the account that do not have a code
  • a code is passed that turns out to be the same for multiple triggers
    In this case, the first trigger that sets an earlier status for the CRM object will be activated.

It is also worth noting that triggers have "Conditions" and the option "Allow transitioning to the previous status," which affect whether the trigger will work or not.

Code Examples

How to Use Examples in Documentation

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"target":"DEAL_57","code":"c5u4m"}' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.automation.trigger
        
curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"target":"DEAL_57","code":"c5u4m","auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/crm.automation.trigger
        
try
        {
        	const response = await $b24.callMethod(
        		"crm.automation.trigger",
        		{
        			target: 'DEAL_57',
        			code: 'c5u4m',
        		}
        	);
        	
        	const result = response.getData().result;
        	console.dir(result);
        }
        catch(error)
        {
        	console.error(error);
        }
        
try {
            $response = $b24Service
                ->core
                ->call(
                    'crm.automation.trigger',
                    [
                        'target' => 'DEAL_57',
                        'code'   => 'c5u4m',
                    ]
                );
        
            $result = $response
                ->getResponseData()
                ->getResult();
        
            if ($result->error()) {
                error_log($result->error());
            } else {
                echo 'Success: ' . print_r($result->data(), true);
            }
        
        } catch (Throwable $e) {
            error_log($e->getMessage());
            echo 'Error triggering automation: ' . $e->getMessage();
        }
        
BX24.callMethod(
            "crm.automation.trigger",
            {
                target: 'DEAL_57',
                code: 'c5u4m',
            },
            function(result) 
            {
                if(result.error())
                    console.error(result.error());
                else
                    console.dir(result.data());
            }
        );
        
require_once('crest.php');
        
        $result = CRest::call(
            'crm.automation.trigger',
            [
                'target' => 'DEAL_57',
                'code' => 'c5u4m'
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Response Handling

HTTP Status: 200

{
            "result": true,
            "time": {
                "start":1718809827.810153,
                "finish":1718809828.541046,
                "duration":0.7308928966522217,
                "processing":0.09834408760070801,
                "date_start":"2024-06-19T15:10:27+00:00",
                "date_finish":"2024-06-19T15:10:28+00:00"
            }
        }
        

Returned Data

Name
type

Description

result
boolean

Result of trigger activation

time
time

Information about the request execution time

Error Handling

HTTP Status: 400

{
            "error":"",
            "error_description":"Target is not set."
        }
        

Name
type

Description

error
string

String error code. It may consist of digits, Latin letters, and underscores

error_description
error_description

Textual description of the error. The description is not intended to be shown to the end user in its raw form

Possible Error Codes

Code

Error Message

Description

Empty string

Target is not set.

The required parameter target was not provided

Empty string

Incorrect target format.

The target parameter was not provided in the required format (Required format TYPENAME_ID)

Empty string

Target is not found.

An incorrect TYPENAME was provided in the target parameter

ACCESS_DENIED

Access denied! There are no permissions to update the entity.

The user did not pass the permission check to trigger the automation.

Empty string

Access denied.

The user did not pass the preliminary permission check for CRM access

Statuses and System Error Codes

HTTP Status: 20x, 40x, 50x

The errors described below may occur when calling any method.

Status

Code
Error Message

Description

500

INTERNAL_SERVER_ERROR
Internal server error

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

500

ERROR_UNEXPECTED_ANSWER
Server returned an unexpected response

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

503

QUERY_LIMIT_EXCEEDED
Too many requests

The request intensity limit has been exceeded

405

ERROR_BATCH_METHOD_NOT_ALLOWED
Method is not allowed for batch usage

The current method is not allowed to be called using batch

400

ERROR_BATCH_LENGTH_EXCEEDED
Max batch length exceeded

The maximum length of parameters passed to the batch method has been exceeded

401

NO_AUTH_FOUND
Wrong authorization data

Invalid access token or webhook code

400

INVALID_REQUEST
Https required

The methods must be called using the HTTPS protocol

503

OVERLOAD_LIMIT
REST API is blocked due to overload

The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support

403

ACCESS_DENIED
REST API is available only on commercial plans

The REST API is available only on commercial plans

403

INVALID_CREDENTIALS
Invalid request credentials

The user whose access token or webhook was used to call the method lacks permissions

404

ERROR_MANIFEST_IS_NOT_AVAILABLE
Manifest is not available

The manifest is not available

403

insufficient_scope
The request requires higher privileges than provided by the webhook token

The request requires higher privileges than those provided by the webhook token

401

expired_token
The access token provided has expired

The provided access token has expired

403

user_access_error
The user does not have access to the application

The user does not have access to the application. This means that the application is installed, but the account administrator has allowed access to this application only for specific users

500

PORTAL_DELETED
Portal was deleted

The public part of the site is closed. To open the public part of the site on an on-premise installation, disable the option "Temporary closure of the public part of the site". Path to the setting: Desktop > Settings > Product Settings > Module Settings > Main Module > Temporary closure of the public part of the site

Continue Learning