All Collections
Working with Cloud Code
Use WebHook with WebHookSpy
Use WebHook with WebHookSpy

webhook, headers, JSONbody

Jason Liang avatar
Written by Jason Liang
Updated over a week ago

WebHookSpy is used to monitor the parameters being sent to a webhook on Portal. The following example describes how to use it within a webhook associated script.

Step 1: Create a script from portal Design | Clould Code | Scripts

  • Set the request parameters which desired to show on portal log in script.

// Some services (like Facebook!) send parameters with periods in them.
// MongoDB doesn't like those - so we need to substitute "_" for the periods
// before logging them to the global entity.
function safeMap(aMap) {
    var newMap = {};
    var newKey = "";

    for (var key in aMap) {
        newKey = key.replace(/\./g, "_");
        newMap[newKey] = aMap[key];

    return newMap;


// Clone the request parameters
var webHookParms = JSON.parse(JSON.stringify(data));

// Make the arguments and parameters mongoDB-safe
webHookParms.headers = safeMap(data.headers);
webHookParms.parameters = safeMap(data.parameters);

var response = {};

bridge.logInfoJson("Received the webhook start...", data);
  • continue writing the main part of script (varies on user's intention). 

  • set log to record the request parameter.

// Log the safe version of the parameters received
var logService = bridge.getLogServiceProxy();
logService.logInfo("Webhook [ " + webHookParms.requestUrl + " ] - dumping parameters...", JSON.stringify(webHookParms));

// Construct a response
response.jsonResponse = {};
response.message = "Webhook received";
response.jsonResponse.receivedInCCdata = data;

Step 2: Go to portal Design | Could Code | Webhook, create a new webhook link it to the cloud code script just created and save it, copy the generated URL for test. 

Note: When the WebHook has been configured to require a secret header, a header named "x-bc-secret" must be included in the HTTP call from the caller site.
Step 3: Test it from postman.

Step 4: Monitor the info log from portal Monitoring | Global Monitioring | Recent Errors.


Did this answer your question?