Creating a Webhook for MERCIGLOBAL Cloud ERP
This guide outlines the process of creating a webhook for integrating with MERCIGLOBAL Cloud ERP. Webhooks allow external systems to send real-time data updates to your ERP environment.
🛠️ Webhook Setup Instructions
Create a new PHP file, e.g., my_webhook.php
, and insert the following code snippet:
<?php
session_start();
require './main_webservices.php'; // Initialises the environment for MERCIGLOBAL Cloud ERP.
// Check and set the passed URL parameters to internal variables
$key = isset($_GET['key']) ? $_GET['key'] : '';
$ename = isset($_GET['ename']) ? $_GET['ename'] : '';
$tname = isset($_GET['tname']) ? $_GET['tname'] : '';
// Create control variable for information exchange
$data = array();
$data['status'] = 'success';
$data['reason'] = '';
// Error handling for missing/invalid variables
if (empty($key)){
$data['status'] = 'failed';
$data['reason'] = 'Missing access key';
}
else if($key !== $code){
$data['status'] = 'failed';
$data['reason'] = 'Invalid access key';
}
else if(empty($ename)){
$data['status'] = 'failed';
$data['reason'] = 'Missing Event name';
}
else if(empty($tname)){
$data['status'] = 'failed';
$data['reason'] = 'Missing Trainer name';
}
// Execute query if all validations pass
if ($data['status'] == 'success'){
BeginTran();
$cQ = "INSERT INTO #mst_event (eventname, trainername, operatorid)
VALUES ('$ename', '$tname', 1)";
$res = myexecute($cQ);
Commit();
}
// Output the response
echo json_encode($data);
?>
🔍 Key Points
- Environment Initialization:
main_webservices.php
sets up necessary configurations for the ERP. - Parameter Validation: Ensures required parameters
key
,ename
, andtname
are provided. - Security: Validate access keys to prevent unauthorized actions.
- Transactional Control: Database operations are wrapped within transaction blocks for consistency.
- Response Format: JSON output is returned indicating success or failure.
🧩 Use Cases
- Integrating third-party registration forms.
- Triggering event creation from external training management systems.
- Automating event logging via API.
📌 Recommendations
- Always validate and sanitize input to avoid SQL injection.
- Maintain a secure and secret access key.
- Log all webhook calls for audit purposes.
For further assistance or custom webhook implementations, please contact the MERCIGLOBAL Cloud ERP support team.