-
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.
-
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.
-
P Paul Winterhalder moved this topic from S2S APIs on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login