Skip to main content

Hooks - Test

Endpoint​

/i/hook/test

Overview​

Runs a hook configuration with provided mock input and returns execution results.

Authentication​

Pass api_key or auth_token as a query parameter, or send countly-token as a header. See Authentication.

Permissions​

Requires hooks Create permission.

Request Parameters​

ParameterTypeRequiredDescription
hook_configJSON String (Object)YesJSON-stringified hook configuration to test.
mock_dataJSON String (Object)YesJSON-stringified input payload passed to trigger processing.
app_idStringConditionalRequired for non-global-admin users.
api_keyStringConditionalRequired if auth_token is not provided.
auth_tokenStringConditionalRequired if api_key is not provided.

hook_config Object Structure​

FieldTypeRequiredDescription
nameStringConditionalRequired when _id is not present.
descriptionStringNoHook description.
_idStringNoOptional existing ID; test flow sets internal rule ID to null before execution.
appsArrayConditionalRequired when _id is not present.
triggerObjectConditionalRequired when _id is not present.
trigger.typeStringConditionalTrigger type to instantiate for test run.
trigger.configurationObjectConditionalTrigger settings for selected trigger type.
effectsArrayConditionalRequired when _id is not present.
effects[].typeStringConditionalEffect type to execute in sequence.
effects[].configurationObjectConditionalEffect settings for selected effect type.
enabledBooleanConditionalRequired when _id is not present.

Decoded hook_config example:

{
"name": "Test HTTP effect",
"description": "Validate outgoing call payload",
"apps": ["6991c75b024cb89cdc04efd2"],
"trigger": {
"type": "InternalEventTrigger",
"configuration": {
"eventType": "/cohort/enter"
}
},
"effects": [
{
"type": "HTTPEffect",
"configuration": {
"method": "post",
"url": "https://example.com/webhooks/countly",
"requestData": "{\"uid\":\"{{uid}}\"}",
"headers": {
"Content-Type": "application/json"
}
}
}
],
"enabled": true
}

Decoded mock_data example:

{
"app_id": "6991c75b024cb89cdc04efd2",
"uid": "user_12345",
"event": "/cohort/enter"
}

Examples​

Test a hook with mock data​

/i/hook/test?
app_id=6991c75b024cb89cdc04efd2&
api_key=YOUR_API_KEY&
hook_config={
"name":"Test HTTP effect",
"description":"Validate outgoing call payload",
"apps":["6991c75b024cb89cdc04efd2"],
"trigger":{"type":"InternalEventTrigger","configuration":{"eventType":"/cohort/enter"}},
"effects":[{"type":"HTTPEffect","configuration":{"method":"post","url":"https://example.com/webhooks/countly","requestData":"{\"uid\":\"{{uid}}\"}"}}],
"enabled":true
}&
mock_data={
"app_id":"6991c75b024cb89cdc04efd2",
"uid":"user_12345",
"event":"/cohort/enter"
}

Response​

Success Response​

{
"result": [
{
"is_mock": true,
"params": {
"app_id": "6991c75b024cb89cdc04efd2",
"uid": "user_12345",
"event": "/cohort/enter"
},
"rule": {
"name": "Test HTTP effect",
"description": "Validate outgoing call payload",
"trigger": {
"type": "InternalEventTrigger",
"configuration": {
"eventType": "/cohort/enter"
}
},
"effects": [
{
"type": "HTTPEffect",
"configuration": {
"method": "post",
"url": "https://example.com/webhooks/countly",
"requestData": "{\"uid\":\"{{uid}}\"}",
"headers": {
"Content-Type": "application/json"
}
}
}
],
"enabled": true,
"_id": null
},
"logs": []
},
{
"is_mock": true,
"params": {
"app_id": "6991c75b024cb89cdc04efd2",
"uid": "user_12345",
"event": "/cohort/enter"
},
"effect": {
"type": "HTTPEffect",
"configuration": {
"method": "post",
"url": "https://example.com/webhooks/countly",
"requestData": "{\"uid\":\"{{uid}}\"}",
"headers": {
"Content-Type": "application/json"
}
}
},
"logs": []
}
]
}

Response Fields​

FieldTypeDescription
resultArrayOrdered test execution results.
result[0]ObjectTrigger execution output snapshot.
result[n].effectObjectEffect descriptor for that effect step.
result[n].logsArrayEffect-level runtime messages/errors captured during execution.

Error Responses​

  • 400
{
"result": "Missing parameter \"api_key\" or \"auth_token\""
}
  • 400
{
"result": "Token not valid"
}
  • 400
{
"result": "Invalid hookConfig"
}
  • 400
{
"result": "Parsed hookConfig is invalid"
}
  • 400
{
"result": "Config invalid"
}
  • 400
{
"result": "Trigger is missing"
}
  • 401
{
"result": "No app_id provided"
}
  • 401
{
"result": "User does not exist"
}
  • 401
{
"result": "User does not have right"
}
  • 401
{
"result": "User is locked"
}
  • 401
{
"result": "App does not exist"
}
  • 401
{
"result": "Token is invalid"
}
  • 403
{
"result": "hook config invalid{...}"
}
  • 503
{
"result": "Hook test failed. ECONNREFUSED: connection refused"
}

Behavior​

Behavior Modes​

ModeConditionResult
Full trigger + effect testValid hook and mock data payloadsRuns trigger, then each effect sequentially, returns ordered result array.
Early returnEffect returns no params payloadReturns accumulated results immediately.

Impact on Other Data​

This endpoint does not insert/update/delete hook documents.

Operational Considerations​

  • Complex effects can make test runs slow because effects are executed sequentially.
  • Some effect types perform real outbound actions during test execution (for example HTTP requests or emails), depending on effect implementation and environment.

Limitations​

  • mock_data parsing errors are surfaced through the generic 503 Hook test failed... branch.
  • Validation for effect configuration is strict for HTTP effects and loose for non-HTTP effects.
Implementation details

Database Collections

CollectionUsed forData touched by this endpoint
countly.membersAuthentication and permission checksReads member account and access metadata.
countly.appsApp validation for non-global-admin usersReads app context during permission validation.