API Reference - Widgets
Link: https://support.brilliantdirectories.com/support/solutions/articles/12000108056
← Back to API Reference | Getting Started
Widgets
Widgets are reusable HTML/CSS/JS components that power the front-end of your Brilliant Directories website. They can be created, modified, and rendered via the API.
data_widgets — DB table: data_widgets/get responses merge platform Default values (an uncustomized record is returned from the platform Defaults with is_default: true) and, based on the admin account that created the API key, honor the same visibility rules as the View Widgets page (/admin/formViewWidgets.php): widgets whose widget_name is on the admin/Add-On blacklist return a 403 permission error, and forbidden records are silently filtered out of list responses. See Getting Started for details./get list response are limited to those supported by the current version of the software. Widgets that belong only to legacy versions are left out. A widget that supports the current version alongside older ones is still returned, because the check asks whether the current version is among the versions listed in bootstrap_enabled, not whether it is the only one. Widgets customized on the website are returned regardless of the versions they list, and retrieving a single widget by ID is not filtered.The Widget Object
| Field | Type | Description |
|---|---|---|
widget_id | integer | Unique widget ID (primary key, read-only) |
widget_name | string | Widget name/label required on create |
widget_type | string | Widget type (default: Widget) |
widget_data | text | Widget HTML content |
widget_style | text | Widget CSS styles |
widget_javascript | text | Widget JavaScript code |
widget_settings | text | Widget configuration settings (JSON or serialized) |
widget_values | text | Widget variable values |
widget_class | string | CSS class names to apply to the widget container |
widget_viewport | string | Where the widget appears: front (public pages), admin (admin panel) or all (both) |
widget_html_element | string | HTML element type wrapping the widget (default: div) |
div_id | string | HTML ID attribute for the widget container |
short_code | string | Shortcode reference for this widget |
bootstrap_enabled | string | The software version the widget supports. A widget customized on the website holds a single version number, 4 on current websites; a list sent in an update is saved as its first number. Default widgets can list several versions, comma-separated (4,3). This is the value the Widget Manager's Software Version filter reads. It is not a true or false flag. |
ssl_enabled | integer | 1 if SSL/HTTPS is enabled for this widget |
mobile_enabled | integer | 1 if mobile viewport is enabled |
file_type | string | File type of the widget |
date_updated | string | Date widget was last updated |
updated_by | string | User who last updated this widget |
revision_timestamp | timestamp | Last modified timestamp (auto-updated) |
customize | string | Virtual field for widget customization context |
fromcron | string | Virtual field indicating cron execution context |
List Widgets
curl -X GET "https://www.yourdomain.com/api/v2/data_widgets/get?limit=25" \ -H "X-Api-Key: your-api-key-here"
Retrieve a Widget
curl -X GET "https://www.yourdomain.com/api/v2/data_widgets/get/500" \ -H "X-Api-Key: your-api-key-here"
Create a Widget
curl -X POST "https://www.yourdomain.com/api/v2/data_widgets/create" \ -H "X-Api-Key: your-api-key-here" \ -d "widget_name=My+Custom+Banner" \ -d "widget_data=%3Ch2%3EWelcome%21%3C%2Fh2%3E"
widget_viewport set to front and bootstrap_enabled set to 4, whatever values the request sends. To show the widget in the admin panel or everywhere, change widget_viewport with an update.Update a Widget
curl -X PUT "https://www.yourdomain.com/api/v2/data_widgets/update" \ -H "X-Api-Key: your-api-key-here" \ -d "widget_id=500" \ -d "widget_name=Updated+Banner" \ -d "widget_data=%3Ch2%3ENew+Content%21%3C%2Fh2%3E"
Delete a Widget
curl -X DELETE "https://www.yourdomain.com/api/v2/data_widgets/delete" \ -H "X-Api-Key: your-api-key-here" \ -d "widget_id=500"
Render a Widget
Returns the rendered HTML output of a widget, with all template variables processed. Useful for previewing widget output or embedding rendered content in external applications.
Example Request
curl -X POST "https://www.yourdomain.com/api/v2/data_widgets/render" \ -H "X-Api-Key: your-api-key-here" \ -d "widget_id=500"
Example Response
{
"status": "success",
"message": "Widget rendered successfully",
"name": "My Widget Name",
"output": "<h2>Welcome!</h2>"
}A success response means the widget's code ran without a PHP error.
Error Response
When the widget's PHP code fails, the call returns HTTP 400 with status set to error. The message names the widget, the PHP error and the line of the widget's code where it happened, in the form Widget error in '<widget name>': <PHP error> on line <n>, and line holds the line number on its own. name and output are still returned, and output holds whatever the widget printed before the error. Fatal errors and a widget that stops the request (EG with exit()) are reported the same way; when no line is known, line is 0 and the message has no line number.
{
"status": "error",
"message": "Widget error in 'My Widget Name': Call to undefined function my_helper() on line 4",
"name": "My Widget Name",
"output": "<h2>Welcome!</h2>\n<!-- Widget error: My Widget Name -->",
"line": 4
}