Local testing

This tutorial explains how to test webhooks configured in your securiCAD Enterprise project locally. Do not use this in production.

Setting up a local web server

To consume the simulation results from the webhooks you need a web server that listens to HTTP POST requests. The example below for a simple Flask application webhook.py that accepts POST requests to the /webhook endpoint.

from flask import Flask, request, Response
import json
import os
app = Flask(__name__)

@app.route('/webhook', methods=['POST'])
def respond():
    print("New post received")
    filedir = os.path.dirname(os.path.realpath('__file__'))
    filename = filedir+"\output.json"
    with open(filename, 'w') as file:
        json.dump(request.json, file)
    return Response(status=200)

To use the above code you need to install Flask and its dependencies by running pip install flask and export the FLASK_APP environment variable export FLASK_APP=webhook.

Start the server with flask run --host= and some output should be presented, with the last message saying Running on http://<Your IP>:5000/. This is the IP address and port the web server is listening on. In other words where we need to direct the webhook POST message coming from securiCAD Enterprise.

Go to your Project in securiCAD Enterprise and add a webhook with the URL http://<Your IP>:5000/webhook and start simulating to receive simulation results in your local web server.