Your issue involves three interconnected problems: API endpoint versioning, widget authentication, and error handling in widgets. Let me address each systematically.
1. API Endpoint Versioning:
Zoho CRM 2023 introduced significant changes to the analytics and reporting API structure. The getReport method you’re using is part of the older API pattern. For analytics reports specifically, you need to use the correct v3 endpoint with proper versioning:
ZOHO.CRM.API.getOrgVariable("reportId").then(function(data) {
const reportId = data.Success.Content;
ZOHO.CRM.HTTP.get({
url: "https://www.zohoapis.com/crm/v3/settings/analytics/reports/" + reportId
})
});
Note that analytics reports are accessed through the ‘/settings/analytics/reports/’ endpoint, not the standard ‘/modules/reports/’ path. This is a critical distinction in v3.
2. Widget Authentication:
The OAUTH_SCOPE_MISMATCH error indicates your widget doesn’t have the correct permissions. For analytics reports in Zoho 2023, you need multiple scopes:
- ‘ZohoCRM.settings.reports.READ’ (for accessing report definitions)
- ‘ZohoCRM.analytics.reports.READ’ (for reading analytics data)
- ‘ZohoCRM.settings.all’ (if you need to access custom report configurations)
Update your widget manifest (plugin-manifest.json) to include:
"permissions": [
"ZohoCRM.settings.reports.READ",
"ZohoCRM.analytics.reports.READ"
]
After updating the manifest, you must reinstall the widget in production. Simply redeploying won’t update the OAuth scopes - you need to go through the installation flow again to get the new permissions authorized.
3. Error Handling in Widgets:
Your current error handling is too basic for production use. Implement comprehensive error handling that distinguishes between different failure scenarios:
ZOHO.CRM.HTTP.get({
url: reportEndpoint
}).then(function(response) {
if (response.status === 200) {
displayData(JSON.parse(response.body));
} else {
handleError(response);
}
}).catch(function(error) {
logError("API call failed", error);
});
function handleError(response) {
// Pseudocode - Error handling steps:
// 1. Check response status code (403, 401, 404, etc.)
// 2. Parse error message from response body
// 3. Display user-friendly error in widget UI
// 4. Log detailed error to console for debugging
// 5. Implement retry logic for transient failures
}
Additional Troubleshooting:
Verify the report exists in production with the same ID. As mentioned in earlier replies, report IDs are environment-specific. Use the Zoho CRM UI to find the correct production report ID.
Check if the report has custom security settings. Some analytics reports in Zoho 2023 have role-based access controls that are separate from the API permissions. The widget’s connected user account must have actual permission to view the report in the CRM interface.
For dashboard widgets specifically, ensure you’re using the correct connection scope. Dashboard widgets sometimes require ‘ZohoCRM.dashboards.ALL’ scope to function properly, even when accessing other resources.
Finally, implement a fallback mechanism in your widget. If the analytics API fails, display a meaningful error message to users rather than a blank widget. This improves the user experience while you troubleshoot the underlying permission issue.