Excellent question - here’s the complete solution covering all three focus areas:
Widget API Endpoint:
The widget framework uses a multi-layer resolution system:
- Widget code references data source by key (e.g., ‘customMetrics’)
- Framework looks up key in application options to get actual endpoint
- Endpoint is resolved relative to application context (UI app or microservice)
For custom microservices, the endpoint path in your widget should be relative to the microservice base:
// In widget component
this.dataService.fetch('customMetrics', {params: {...}})
// NOT: this.http.get('/service/custom-analytics/api/metrics')
Data Source Registration:
Register via application options API during app deployment:
POST /application/applications/{yourAppId}/options
{
"category": "dataSource",
"key": "customMetrics",
"value": "/service/custom-analytics/api/metrics"
}
This must happen BEFORE dashboard loads widgets. Include this in your application’s deployment script or initialization hook.
Widget manifest (cumulocity.json) declares capability:
{
"dataSources": [
{"name": "customMetrics", "type": "c8y_CustomDataSource"}
]
}
API Path Correctness:
Common mistakes causing 404:
- Using absolute paths in widget code (wrong)
- Forgetting /service/ prefix in options registration (wrong)
- Mismatched key names between manifest and options (wrong)
- Missing microservice context path (wrong)
Correct pattern:
- Manifest: declares “customMetrics” data source
- Options: maps “customMetrics” → “/service/custom-analytics/api/metrics”
- Widget: references “customMetrics” (framework resolves full path)
Microservice Configuration:
Ensure your microservice manifest includes:
{
"contextPath": "custom-analytics",
"requiredRoles": ["ROLE_APPLICATION_MANAGEMENT_READ"],
"resources": {
"memory": "256M"
}
}
Debugging Steps:
- Verify microservice is subscribed: Administration → Applications → custom-analytics (should show ‘Subscribed’)
- Test direct access: GET /service/custom-analytics/api/metrics (should return 200)
- Check application options: GET /application/applications/{appId}/options (should list your customMetrics entry)
- Verify widget manifest syntax: ensure dataSource name matches options key exactly
- Clear browser cache and reload dashboard
Your 404 error is caused by missing application options registration. The widget framework can’t resolve ‘customMetrics’ to the actual microservice endpoint without the options API mapping. Register the data source as shown above and ensure the key names match across manifest, options, and widget code.