If you’ve just literally copied and pasted to test then you are missing the import wixCrm call and the onReady call at the beginning of your code.
Plus you need to have changed the url line to a url from your website, otherwise you will always get the undefined error!
“actionTarget”: {“url”: " http://mysite.com/somepage "}, - this needs to be your website page.
hey,
Sorry I hadn’t mentioned it that I had included it as its a default thing I always do first of all. Just gave it a go with these settings below and still comes up with
TypeError: undefined is not an object (evaluating '_wixCrmBackend2.default.notifications')
The error message is associated with line 5 of the code which is
I just noticed this too. Looks like its down or something. When you go to type in ‘import’ at the top, it doesn’t even give the option for 'import wixCrm from ‘wix-crm-backend’ the only backend option it has it is 'import wixCrmBackend from ‘wix-crm-backend’. It looks like we are just going to have to wait until this gets taken care of!
-Morgan
I hope this helps to anyone that wants to know!
To make Notifications works please follow these steps:
Create a Backend Code page call it Notifications
Place following code in Backend/Notifications
// !!!!!!!!!! This MUST Go into Backend/Notifications !!!!!!!!! \\
import wixCrm from 'wix-crm-backend';
export function notifyOwnerOnDashboard(title, action,site,role) {
wixCrm.notifications.notify(
title,
["Dashboard", "Browser", "Mobile"],
{
"title" : title,
"actionTitle": action,
"actionTarget": {"url": site},
"recipients": { "role": role}
}
);
console.log('Notification sent')
}
Go to desire page to insert Front end Code.
// Place this in desired Front End Code Page \\
import {notifyOwnerOnDashboard} from 'backend/notifications';
export function Notifyteam(event) {
const title = "I'm a title"
const action = "This is what I have done" ;
const site = "This is the website I want you to visit" ; // use full URL link
const role = "All_Contributors";
notifyOwnerOnDashboard(title,action,site,role)
}
Good work Chris and thanks for pasting up the working code example below too, let’s hope that the Wix team can get this changed asap as it does seem a bit odd that there is no reference to it being placed in the backend in the api section.
I had implemented Chris’ code and it had been working beautifully for a few weeks, but it just stopped working about 3 days ago quite inexplicably, which leads me to believe something may have changed on wix side.
Does anyone have any insights on this perhaps - I get the following errors on the developer console when I test the notification function.
Notification sent
Unhandled rejection Error: server responded with 403 - "<html>\r\n<head><title>403 Forbidden</title></head>\r\n<body>\r\n<center><h1>403 Forbidden</h1></center>\r\n<hr><center>nginx/1.15.10</center>\r\n</body>\r\n</html>\r\n" at handleServerError (/dynamic-modules/edm_root/e7766210-e9d2-11e9-a216-c7095c2ca2bb/node_modules/@wix/wix-crm-backend/src/notifications/api.ts:162:11) at Object.<anonymous> (/dynamic-modules/edm_root/e7766210-e9d2-11e9-a216-c7095c2ca2bb/node_modules/@wix/wix-crm-backend/src/notifications/api.ts:109:9) at Generator.throw (<anonymous>) at rejected (/dynamic-modules/edm_root/e7766210-e9d2-11e9-a216-c7095c2ca2bb/node_modules/@wix/wix-crm-backend/dist/src/notifications/api.js:5:65) at bound (domain.js:396:14) at runBound (domain.js:409:12) at tryCatcher (/elementory/node_modules/bluebird/js/main/util.js:26:23) at Promise._settlePromiseFromHandler (/elementory/node_modules/bluebird/js/main/promise.js:510:31) at Promise._settlePromiseAt (/elementory/node_modules/bluebird/js/main/promise.js:584:18) at Async._drainQueue (/elementory/node_modules/bluebird/js/main/async.js:128:12) at Async._drainQueues (/elementory/node_modules/bluebird/js/main/async.js:133:10) at Immediate.Async.drainQueues [as _onImmediate] (/elementory/node_modules/bluebird/js/main/async.js:15:14) at runCallback (timers.js:705:18) at tryOnImmediate (timers.js:676:5) at processImmediate (timers.js:658:5) at process.topLevelDomainCallback (domain.js:121:23)
@deleteduser Thanks Heath, but which page exactly can it not access - the URL associated to notification function definitely does exist and is accessible.
@deleteduser I have the same problem, same error. If it helps - here is the link to the page that generates that same 403 error message when I try to send the notification. https://www.cutest.house/test
import {notifyOwnerOnDashboard} from 'backend/notifications';
$w.onReady(function () {
export function notifyOwner() {
const title = "I'm a title";
const action = "This is what I have done";
const site = "https://www.wix.com"; // use full URL link
const role = "Owner";
notifyOwnerOnDashboard()
}
}
@givemeawhisky Removing the file type at the end of the backend import didn’t help.
Changing the file type to .js caused this error:
Access to backend script ‘backend/notifications.js’ denied! Client-side scripts can only import web-modules (.jsw) from backend code context.
@sailorcihan Did you manage to actually get the notifications api to work at all?
I haven’t been able to get any of them to work. I have tried every possible way, i think that the notification system is broken due to the new Module Web Permissions option, or there has been a change interanally on the Wix side.
Could one of the Corvid Dev team please let us know, as this is causing major issues for various clients not being informed or certain changes on thier site.