Module: factory.core/ObjHookEdit.py
Extends: ObjHook.ObjHook
Provides a simple load/save interface for both inbound and outbound webhooks. This module handles complete webhook configurations in single operations, automatically managing parameters and validations.
ObjHookEdit is called by ObjApiEdit when saving entire API configurations that include webhook components.
Package Management: Package is determined automatically via get_package(). Do NOT include Package in webhook configurations - it will be set based on the active package context.
Cascade Operations: All delete operations cascade automatically. Parameters and validations are always deleted with their parent webhook.
ObjApiEdit (API orchestration)
↓ calls
ObjHookEdit (Webhook persistence)
↓ manages
Database Tables:
- def_webhook (PK: WebhookCode, Package)
- def_webhook_parameters (PK: WebhookCode, Package, Parameter)
- def_webhook_validations (PK: WebhookCode, Package, Description)
- def_webhook_output_validations (PK: WebhookCode, Package, Description)
Default Folder: local.documents/webhooks/
Webhook configurations can be exported to and imported from YAML files in this folder. Package field is automatically excluded from exports and determined by get_package() on import.
load(webhook_code)Load complete webhook configuration from database.
Automatically loads:
Args:
webhook_code (str): Webhook code to loadReturns: dict with keys:
webhook: Main webhook dataparameters: All parametersinput_validations: Input validation rulesoutput_validations: Output validation rulesReturns empty {} if webhook not found.
Example:
from ObjHookEdit import ObjHookEdit
hook_edit = ObjHookEdit()
config = hook_edit.load("TESTHOOK")
if config:
print(f"Loaded: {config['webhook']['WebhookCode']}")
print(f"Parameters: {len(config['parameters'])}")
print(f"Input validations: {len(config['input_validations'])}")
print(f"Output validations: {len(config['output_validations'])}")
save(webhook_config)Save complete webhook configuration to database.
Automatically saves:
Args:
webhook_config (dict): Complete webhook configuration
webhook (main webhook data)parameters, input_validations, output_validationsReturns: bool - True if saved successfully
Save Process:
Example:
hook_edit = ObjHookEdit()
config = {
"webhook": {
"WebhookCode": "SCORECHECK",
"Direction": "IN",
"Type": "INIT",
"Httpmethod": "POST",
"PayloadType": "JSON",
"Description": "Credit score check",
"Buildstructure": "Y",
"Buildvalidation": "Y",
"Buildoutputvalidation": "Y",
"Active": "Y"
},
"parameters": [
{
"Parameter": "customer_id",
"Rank": 1,
"PostType": "POST",
"ValueType": "string",
"Required": "Y",
"Description": "Customer ID"
},
{
"Parameter": "score",
"Rank": 1,
"PostType": "RETURN",
"ValueType": "int",
"Description": "Credit score"
}
],
"input_validations": [
{
"Description": "Customer ID required",
"ValidationSql": "SELECT IF(customer_id IS NOT NULL AND customer_id != '', 1, 0)",
"ValidationNote": "Customer ID must be provided",
"Rank": 1
}
],
"output_validations": [
{
"Description": "Score in range",
"ValidationSql": "SELECT IF(score BETWEEN 0 AND 1000, 1, 0)",
"ValidationNote": "Score must be 0-1000",
"Rank": 1
}
]
}
hook_edit.save(config)
delete_webhook(webhook_code)Delete webhook and all related data (cascade delete).
Automatically deletes:
Args:
webhook_code (str): Webhook code to deleteReturns: bool - True if deleted successfully
Example:
hook_edit = ObjHookEdit()
hook_edit.delete_webhook("OLDHOOK")
export_to_file(webhook_code, filename=None)Export webhook configuration to YAML file.
Exports complete webhook (excluding Package) to local.documents/webhooks/.
Args:
webhook_code (str): Webhook code to exportfilename (str, optional): Custom filename (defaults to {webhook_code}.yaml)Returns: bool - True if exported successfully
Example:
hook_edit = ObjHookEdit()
# Export with default filename
hook_edit.export_to_file("TESTHOOK")
# Creates: local.documents/webhooks/TESTHOOK.yaml
# Export with custom filename
hook_edit.export_to_file("TESTHOOK", "backup_testhook.yaml")
import_from_file(filename, webhook_code=None)Import webhook configuration from YAML file and save to database.
Loads from local.documents/webhooks/ and saves to current package.
Args:
filename (str): Filename in webhooks folderwebhook_code (str, optional): Override webhook code from fileReturns: bool - True if imported and saved successfully
Example:
hook_edit = ObjHookEdit()
# Import with webhook code from file
hook_edit.import_from_file("TESTHOOK.yaml")
# Import and override webhook code
hook_edit.import_from_file("TESTHOOK.yaml", "TESTHOOK_V2")
list_files()List all webhook YAML files in webhooks folder.
Returns: list[str] - Sorted list of filenames
Example:
hook_edit = ObjHookEdit()
files = hook_edit.list_files()
for filename in files:
print(filename)
export_to_postman(webhook_code, base_url, filename=None)Export webhook as Postman Collection for interactive API testing.
Creates a Postman Collection v2.1 JSON file that can be imported directly into Postman.
Args:
webhook_code (str): Webhook code to exportbase_url (str): Base URL for the API (e.g., "https://api.example.com")filename (str, optional): Custom filename (defaults to {webhook_code}.postman_collection.json)Returns: bool - True if exported successfully
Example:
hook_edit = ObjHookEdit()
# Export with base URL
hook_edit.export_to_postman("TESTHOOK", "https://api.example.com")
# Creates: local.documents/webhooks/postman/TESTHOOK.postman_collection.json
# Import into Postman:
# 1. Open Postman
# 2. File → Import
# 3. Select the .postman_collection.json file
# 4. Start testing!
Collection includes:
export_to_markdown(webhook_code, filename=None)Export webhook as Markdown documentation.
Creates comprehensive human-readable documentation in Markdown format.
Args:
webhook_code (str): Webhook code to exportfilename (str, optional): Custom filename (defaults to {webhook_code}.md)Returns: bool - True if exported successfully
Example:
hook_edit = ObjHookEdit()
# Export to Markdown
hook_edit.export_to_markdown("TESTHOOK")
# Creates: local.documents/webhooks/docs/TESTHOOK.md
Documentation includes:
Perfect for:
Main webhook definition table.
Primary Key: (WebhookCode, Package)
Key Fields:
Direction: 'IN' (inbound) or 'OUT' (outbound)Type: INIT, REMOTE, PROXY, GUIHttpmethod: GET, POST, PUT, DELETE, PATCHBaseUrl: Endpoint URLPayloadType: JSON, XML, FORMBuildstructure: Build input structure from parameters (Y/N)Buildvalidation: Execute input validations (Y/N)Buildoutputvalidation: Execute output validations (Y/N)HookLookupSql: SQL to retrieve webhook result dataHookpayloadsql: SQL to build request payloadPreSql: SQL executed before webhook callPostSql: SQL executed after webhook callNotifyOnCompletion: Send notification on success (Y/N)NotifyOnError: Send notification on error (Y/N)NotifyCompletionCode: Notification code for successNotifyErrorCode: Notification code for errorsInput and output parameter definitions.
Primary Key: (WebhookCode, Package, Parameter)
Key Fields:
PostType: 'POST', 'GET', 'RETURN' (RETURN = output)ValueType: string, int, float, boolRequired: Y/NDefaultValue: Default if not providedRank: Processing orderInput validation rules (pre-execution).
Primary Key: (WebhookCode, Package, Description)
Key Fields:
ValidationSql: SQL returning 1=pass, 0=failValidationNote: Human-readable descriptionRank: Execution orderActive: Y/NRemoteConnection: Optional remote DB connectionOutput validation rules (post-execution).
Primary Key: (WebhookCode, Package, Description)
Key Fields: Same as input validations
# Database operations
python factory.core/ObjHookEdit.py load-webhook TESTHOOK
python factory.core/ObjHookEdit.py delete-webhook OLDHOOK
# File operations
python factory.core/ObjHookEdit.py export-webhook TESTHOOK
python factory.core/ObjHookEdit.py export-webhook TESTHOOK --filename backup.yaml
python factory.core/ObjHookEdit.py import-webhook TESTHOOK.yaml
python factory.core/ObjHookEdit.py import-webhook TESTHOOK.yaml --webhook-code TESTHOOK_V2
python factory.core/ObjHookEdit.py list-webhooks
from ObjHookEdit import ObjHookEdit
hook_edit = ObjHookEdit()
config = {
"webhook": {
"WebhookCode": "NEWAPI",
"Direction": "IN",
"Type": "INIT",
"Httpmethod": "POST",
"PayloadType": "JSON",
"Description": "New API endpoint",
"Buildstructure": "Y",
"Active": "Y"
},
"parameters": [
{"Parameter": "id", "Rank": 1, "PostType": "POST", "Required": "Y"},
{"Parameter": "result", "Rank": 1, "PostType": "RETURN"}
]
}
hook_edit.save(config)
hook_edit = ObjHookEdit()
# Load existing
source = hook_edit.load("TESTHOOK")
# Modify
source["webhook"]["WebhookCode"] = "TESTHOOK_V2"
source["webhook"]["Description"] = "TESTHOOK version 2"
# Save as new
hook_edit.save(source)
hook_edit = ObjHookEdit()
# Load existing
config = hook_edit.load("TESTHOOK")
# Modify
config["webhook"]["Description"] = "Updated description"
config["webhook"]["Timeout"] = 120
# Add new parameter
config["parameters"].append({
"Parameter": "new_field",
"Rank": 10,
"PostType": "POST",
"ValueType": "string"
})
# Save changes
hook_edit.save(config)
hook_edit = ObjHookEdit()
hook_edit.delete_webhook("OLDHOOK") # Cascades automatically
hook_edit = ObjHookEdit()
# Export to default location
hook_edit.export_to_file("TESTHOOK")
# Creates: local.documents/webhooks/TESTHOOK.yaml
hook_edit = ObjHookEdit()
# Import from file (saves to current package)
hook_edit.import_from_file("TESTHOOK.yaml")
# Clone by importing with new code
hook_edit.import_from_file("TESTHOOK.yaml", "TESTHOOK_CLONE")
hook_edit = ObjHookEdit()
# Export for version control
hook_edit.export_to_file("PRODUCTION_API")
# Commit: local.documents/webhooks/PRODUCTION_API.yaml
# Deploy to different environment
hook_edit.import_from_file("PRODUCTION_API.yaml")
# Saved to current package automatically
ObjApiEdit calls ObjHookEdit when saving APIs with webhooks:
from ObjHookEdit import ObjHookEdit
class ObjApiEdit(ObjApi.ObjApi):
def save_api_with_webhooks(self, api_code, webhooks):
hook_edit = ObjHookEdit(self.DB)
for webhook_config in webhooks:
hook_edit.save(webhook_config)
Never specify Package: Package is determined automatically via get_package()
Load before Update: Always load existing webhook before modifying to preserve all fields
Complete Configurations: Use load() and save() for all operations - they handle everything
Validation SQL: Validation SQL must return 1=pass, 0=fail. Use placeholder $guid$ for runtime value substitution
Parameter Ranks: Assign unique ranks to maintain consistent ordering
Version Control: Export webhooks to YAML for version control. Files are stored in local.documents/webhooks/ which can be committed to git
Environment Migration: Use export/import to move webhooks between environments. Package is determined by target environment's get_package()
All methods log errors via self.debug(). Check return values:
load() returns {} if webhook not foundsave() returns False on errordelete_webhook() returns False on errorObjHook.py - Base webhook functionalityObjApiEdit.py - API editing and documentationWebHooks.py - Webhook execution engineObjHook.yaml - Database schemas and queries