Couchbase Webhook is not triggered

I have this sync gateway config:
{
“adminInterface”: “:4985”,
“interface”: “:4984”,
“log”:[“REST+”,“CRUD+”,“Events”,“Events+”,“HTTP+”],
“databases”: {
“suites_bucket”: {
“server”: “http://someurl.com”,
“bucket”: “suites”,
“username”: “Administrator”,
“password”: “Password”,
“enable_shared_bucket_access”: true,
“import_docs”: true,
“num_index_replicas”: 0,
“use_views”: true,
“users”: {
“GUEST”: { “disabled”: false, “admin_channels”: ["*"] },
“sync_gateway”: {“password”: “pass1234”}
},
“event_handlers”:{
“document_changed”:[
{
“handler”:“webhook”,
“url”:“https://someurl.com”,
“filter”:function(doc){ if(doc.docType=="someType"){ return true; } return false; }
}
]
}
}
}
}

When starting the sg service i got this notif:
Events: Creating JSEventFunction
Events: Registered event handler: Webhook handler [https://someurl.com], for event type 0
Events: Starting event manager with max process:500, wait time: 100 ms

But when app is syncing a document with docType==“someType” the webhook is not being triggered

At an initial glance, the event handler config looks OK.
So I suspect that that the none of the docs mach the criteria that you are filtering on -

In your filter function, include the following log and see what the output says. Something like this …

"event_handlers": {
      "document_changed": [
        {"handler": "webhook",
         "url": "http://someurl.com/type_A",
         "filter": `function(doc) {
        console.log("IN HERE with " + doc.docType)
                return true;
            }`
         }
     ]
  }

Also unrelated to the issue, I noticed that you have “use_views” set to TRUE. Any reason why you have opted out of using GSI/query which is the default (and preferred) option ?

Hi Priya,

You’re right. The webhook is being triggered after I removed the filter.

Should my endpoint expect 1 document per sync or can it be in bulk?

Maybe the problem is on my endpoint. But I encountered issue on restarting the sync gateway 3 times within 30 minutes, sync gateway service status is online and running but db_url:4985 is not responding. Rebooting the server solves the issue.

Also, thanks for pointing out the use_views attribute.

Will update this thread with my progress.

Thank you

So did you see a document with the “docType” property set to what you expected? Can you share the log of what you see? Filters should work as long as there is a matching document. So just want to confirm that you weren’t seeing a match. You should see one document …not bulk

Yup. I added document using admin rest api and it matched on the log.

And after few restarts of sync gateway I encountered this on logs:

2021-01-06T23:05:46.967+08:00 ==== Couchbase Sync Gateway/2.7.3(3;33d352f) CE ====
2021-01-06T23:05:46.968+08:00 [WRN] Using deprecated config option: "log". Use "logging.console.log_keys" instead. -- rest.(*ServerConfig).deprecatedConfigLoggingFallback.func5() at config.go:763
2021-01-06T23:05:46.968+08:00 [WRN] Deprecated log key: "REST+" found. Changing to: "REST". -- base.ToLogKey.func1() at log_keys.go:175
2021-01-06T23:05:46.968+08:00 [WRN] Invalid log key: REST+ -- base.ToLogKey.func2() at log_keys.go:185
2021-01-06T23:05:46.968+08:00 [WRN] Deprecated log key: "CRUD+" found. Changing to: "CRUD". -- base.ToLogKey.func1() at log_keys.go:175
2021-01-06T23:05:46.968+08:00 [WRN] Deprecated log key: "Events+" found. Changing to: "Events". -- base.ToLogKey.func1() at log_keys.go:175
2021-01-06T23:05:46.968+08:00 [INF] Logging: Console to stderr
2021-01-06T23:05:46.968+08:00 [INF] Logging: Files to /home/sync_gateway/logs
2021-01-06T23:05:46.968+08:00 [INF] Logging: Console level: info
2021-01-06T23:05:46.968+08:00 [INF] Logging: Console keys: [CRUD Events HTTP HTTP+]
2021-01-06T23:05:46.968+08:00 [INF] Logging: Redaction level: none
2021-01-06T23:05:46.968+08:00 [INF] requestedSoftFDLimit < currentSoftFdLimit (5000 < 65535) no action needed
2021-01-06T23:05:46.968+08:00 [INF] Logging stats with frequency: 1m0s
2021-01-06T23:05:46.968+08:00 [INF] Opening db /{db} as bucket "{bucket}", pool "default", server <{server_url}:8091>
2021-01-06T23:05:46.968+08:00 [INF] GoCBCustomSGTranscoder Opening Couchbase database {suites} on <{server_url}:8091> as user "Administrator"
2021-01-06T23:05:46.970+08:00 [INF] Auth: Attempting credential authentication {server_url}:8091?http_idle_conn_timeout=90000&http_max_idle_conns=64000&http_max_idle_conns_per_host=256&kv_pool_size=2&n1ql_timeout=75000&operation_tracing=false
2021-01-06T23:05:46.977+08:00 [INF] Successfully opened bucket {bucket_name}
2021-01-06T23:05:47.049+08:00 [INF] Set query timeouts for bucket {bucket} to cluster:1m15s, bucket:1m15s
2021-01-06T23:05:47.049+08:00 [INF] Initializing indexes with numReplicas: 0...
2021-01-06T23:05:47.946+08:00 [INF] Query: Index sg_channels_x1 doesn't exist, creating...
2021-01-06T23:05:47.962+08:00 [WRN] Error creating index sg_channels_x1: Error creating index with statement: CREATE INDEX `sg_channels_x1` ON `{bucket}`(ALL (ARRAY [op.name, LEAST(meta().xattrs._sync.sequence,op.val.seq), IFMISSING(op.val.rev,null), IFMISSING(op.val.del,null)] FOR op IN OBJECT_PAIRS(meta().xattrs._sync.channels) END), meta().xattrs._sync.rev, meta().xattrs._sync.sequence, meta().xattrs._sync.flags) with {"retain_deleted_xattr":true,"defer_build":true}.  Error: [3000] Expression not indexable: array [(`op`.`name`), least((((meta().`xattrs`).`_sync`).`sequence`), ((`op`.`val`).`seq`)), ifmissing(((`op`.`val`).`rev`), null), ifmissing(((`op`.`val`).`del`), null)] for `op` in object_pairs((((meta().`xattrs`).`_sync`).`channels`)) end - at , 
 Expression not indexable: (((meta().`xattrs`).`_sync`).`rev`) - at , 
 Expression not indexable: (((meta().`xattrs`).`_sync`).`sequence`) - at , 
 Expression not indexable: (((meta().`xattrs`).`_sync`).`flags`) - at ) - will retry. -- db.(*SGIndex).createIfNeeded.func1() at indexes.go:256
2021-01-06T23:05:47.972+08:00 [WRN] Error creating index sg_channels_x1: Error creating index with statement: CREATE INDEX `sg_channels_x1` ON `{bucket}`(ALL (ARRAY [op.name, LEAST(meta().xattrs._sync.sequence,op.val.seq), IFMISSING(op.val.rev,null), IFMISSING(op.val.del,null)] FOR op IN OBJECT_PAIRS(meta().xattrs._sync.channels) END), meta().xattrs._sync.rev, meta().xattrs._sync.sequence, meta().xattrs._sync.flags) with {"retain_deleted_xattr":true,"defer_build":true}.  Error: [3000] Expression not indexable: array [(`op`.`name`), least((((meta().`xattrs`).`_sync`).`sequence`), ((`op`.`val`).`seq`)), ifmissing(((`op`.`val`).`rev`), null), ifmissing(((`op`.`val`).`del`), null)] for `op` in object_pairs((((meta().`xattrs`).`_sync`).`channels`)) end - at , 
 Expression not indexable: (((meta().`xattrs`).`_sync`).`rev`) - at , 
 Expression not indexable: (((meta().`xattrs`).`_sync`).`sequence`) - at , 

Am I missing something?

OK - So you have confirmed that if you see a document that matching criteria then the URL endpoint is invoked.

The error logs appear unrelated to webhooks question originally posted. Please open a separate post for that - looks like you have switched from views and you are seeing this. And when you create that post, please share details of exactly what triggers this (you say restarts - how many and how frequently? Are you sure your previous restart is completed successfully before you triggered the second restart for instance?), SGW and CBS versions, SG log output from what you assume is a successful start and then the failed restart, the SG config etc.

Also, you may want to take care of the deprecation warnings by updating your config file to use new logging config as defined in our docs.

1 Like