Code Samples
Code
Net Core
[HttpPost]
public IActionResult ReceiveAccuLynxWebhook([FromBody] WebhookPayload payload)
{
// Process the payload data
switch (payload.TopicName)
{
case "job-milestone-changed":
// Handle milestone changed event
break;
default:
// Unknown event type, do nothing
break;
}
// Respond with a 200 OK status code to acknowledge receipt of the payload
return Ok();
}
public class WebhookPayload
{
public string TopicName { get; init; } = string.Empty;
public DateTime EventDateTime { get; set; }
public Guid EventId { get; set; }
public Guid SubscriptionId { get; set; }
public dynamic Event { get; set; } = null!;
}
Node.js (Azure Functions)
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
context.log('JavaScript HTTP trigger function processed a request.');
var responseMessage = '';
var statusCode = 200;
var mySecret = // Get your secret here;
try {
switch(req.body.type){
case 'job-milestone-changed':
// Handle notification
break;
default:
// Unknown type. Do nothing
break;
}
statusCode = 200;
responseMessage = "OK";
}
catch (err) {
context.log(err);
statusCode = 500;
responseMessage = err.toString();
}
context.res = {
status:statusCode,
body: responseMessage
};
}
Python (Azure Functions)
import logging
import azure.functions as func
import json
from hashlib import sha256
import base64
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
try:
req_body = req.get_json()
webhook_type = req_body["topicName"]
match webhook_type:
case "job-milestone-changed":
# Handle Job milestone changed
case other:
# Unknown type. Do nothing
response = "OK"
code=200
except Exception as err:
response = f"Error: {err}"
code = 500
logging.error(err)
return func.HttpResponse(response, status_code=code)
Updated 2 months ago