• Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
brainCloud Forums

How do I code a custom webhook in brainCloud?

Scheduled Pinned Locked Moved Solved APIs
cloud code scriptwebhook
2 Posts 2 Posters 369 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Ima Need-SupportI Offline
    Ima Need-SupportI Offline
    Ima Need-Support
    wrote on last edited by
    #1

    Hi,

    As the subject implies - I am integrating my app with an external service that can call my app via webhooks.

    How would I hook this up using brainCloud?

    Ima.

    1 Reply Last reply
    0
  • Paul WinterhalderP Offline
    Paul WinterhalderP Offline
    Paul Winterhalder brainCloudAdmin
    wrote on last edited by
    #2

    Hi,

    Here are the steps to setting up a webhook to call a custom cloud code script in brainCloud:

    Step 1 - Write your script

    • Go to Design | Cloud Code | Scripts and create your script
    • You might want to just start with a simple script that logs the incoming parameters (see sample below)
    • Be sure to enable the S2S callable field on the Details page.

    Step 2 - Declare the webhook and link it to your script

    • Go to Design | Cloud Code | WebHooks and create your webhook
    • Link it to the script that you just wrote. If you don't see your script in the list, double-check the state of the S2S callable field
    • You can optionally restrict the webhook to be callable via a range of ip ranges (good for additional security)
    • Click [Save] and copy the webhook URL that gets generated

    Step 3 - Go to the external service, and give it your webhook URL

    • This step varies by service of course.

    Step 4 - Trigger the webhook to test

    • This also varies by service. You could use Postman to do it as well.

    Step 5 - Confirm the structure of the incoming parameters

    • It is a bit difficult to figure out what a webhook will send you ahead-of-time
    • The simplest is to invoke the hook, and then examine the results
    • See the sample logging script below for an example
    • Then view the logged input data via Monitoring | Global Monitoring | Recent Errors. Be sure to enable Info -level messages, and click [Refresh]

    Step 6 - Complete the writing of your script

    • Now that you know how the parameters are being sent, you should be good to complete your script.
    • More info on webhook development here - https://getbraincloud.com/apidocs/apiref/?cloudcode#cc-ccscripts-webhooks
    • Good luck!

    Sample script - just dumps parameters:

    var response = {};
    
    bridge.logInfoJson("Script invoked from webhook. Contents of data...", data);
    
    // Return the webhook response
    response.statusOverride = 200;
    response.jsonResponse = {};
    
    response;
    

    Note - you can also view the request sent and response received from your webhook via the Server Logs. For more information on brainCloud logs - see this knowledge base article.

    Hope that helps!

    Paul.

    1 Reply Last reply
    1
  • Paul WinterhalderP Paul Winterhalder moved this topic from S2S APIs on

  • Login

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users