Resolved: wixCrm.notifications.notify not functioning

Hello,
The wixCrm.notifications.notify api function isn’t currently working

It’s generating:

TypeError: undefined is not an object (evaluating '_wixCrmBackend2.default.notifications')

I have literally copy and paste the code from the Corvid Reference Doc to run a test.

export function notifyOwnerOnDashboard() {
  wixCrm.notifications.notify(
    "Notification body", 
    ["Dashboard"], 
    {
      "title": "Notification Title",
      "actionTitle": "Click this!",
      "actionTarget": {"url": "http://mysite.com/somepage"},
      "recipients": {"role": "Owner"}
    }
  );
}
 

Just thought I should flag it!

Thanks
Chris

1 Like

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

wixCrm.notifications.notify(

The code that I added was as follows

export function notifyOwnerOnDashboard(event) {
wixCrm.notifications.notify(
 "Notification body",
        ["Dashboard"], {
 "title": "test",
 "actionTitle": "test title",
 "actionTarget": { "url": "https//www.silvesterdesign.com" },
 "recipients": { "role": "All_Contributors" }
        }
    )
}

In addition I’ve noticed that when you type wixCrm to call its functions, it’s not recognised

Hey Chris,

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

Hey Morgan,
The import function part is not producing as per the reference api, but if you copy and paste it, it still recognises

In terms of the actual API code this needs to go into the backend code structure!

And you simply call it from page code.

When I get to my office, I can show you what you need to do. To make it work.

WIX CORVID team - would be great if you could reflect the api reference for this that it should go backend and not in the page code.

Thanks
Chris

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)

}

For full details on how to decide where it notify’s and who it is sent to please visit Notifications - Velo API Reference - Wix.com

Thank you!

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.

Hello gents,

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.

I think it may be an issue with the following:

handleServerError (/dynamic-modules/edm_root/e7766210-e9d2-11e9-a216-c7095c2ca2bb/node_modules/@wix/wix-crm-backend/src/notifications/api.ts:162:11) 

@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

Have a look at the API Reference for the notify function itself as if you are sending to the site owner’s dashboard, it looks like it has been changed slightly.
https://www.wix.com/corvid/reference/wix-crm-backend.notifications.html#notify

Hence why you are getting this error received back…

"<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"

So from this…

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')
}

To this instead with the “Notification body” in it instead.

Send a notification to the site owner’s Dashboard

import wixCrm from 'wix-crm-backend';

export function notifyOwnerOnDashboard() {
  wixCrm.notifications.notify(
    "Notification body", 
    ["Dashboard"], 
    {
      "title": "Notification Title",
      "actionTitle": "Click this!",
      "actionTarget": {"url": "http://mysite.com/somepage"},
      "recipients": {"role": "Owner"}
    }
  );
}

I’m still getting the same error - did you get it working yourself?

I looked at the API Reference I don’t think its changed from before.

@bradosner

Have you actually just tried changing your code to suit the API Reference?

Also, just try deleting the options in the brackets too of title, action, site and role, so you just simply have the () as the code below.

Plus, add in the other two channels for notification of Browser and Mobile again too.

The code has changed from the original posted in this forum post.

You need to replace the title, line with the “Notification body”, line instead.

ORIGINAL

export function notifyOwnerOnDashboard(title, action,site,role) {
  wixCrm.notifications.notify(
     title, 
     ["Dashboard", "Browser", "Mobile"], 
    { 

NEWER

export function notifyOwnerOnDashboard() {
  wixCrm.notifications.notify(
    "Notification body", 
    ["Dashboard"], 
    {

Like I’ve said previously, that would explain why you are getting the error with the title and the 403 Forbidden etc.

"<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" 

@givemeawhisky

Are you putting this in the backend - if so how do call the function with different arguments?

I’ve tried it exactly as you’ve put it - I’m still getting the same error

@bradosner

Just try the code with the site owner notify part only and see if you still get the same error.

Place following code in Backend/Notifications

import wixCrm from 'wix-crm-backend';

export function notifyOwnerOnDashboard() {
  wixCrm.notifications.notify(
    "Notification body", 
    ["Dashboard"], 
    {
      "title": "Notification Title",
      "actionTitle": "Click this!",
      "actionTarget": {"url": "https://www.wix.com"},
      "recipients": {"role": "Owner"}
    }
  );
}

Go to desire page to insert Front end Code.

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()
}
}

Just as @bradosner , I am getting the same 403 error after altering my code based on @givemeawhisky

FrontEnd:
import {notifyOwnerOnDashboard} from ‘backend/notifications.jsw’;

$w.onReady( function () {
notifyOwnerOnDashboard();
});

BackEnd (based on the example provided by @givemeawhisky :
import wixCrm from ‘wix-crm-backend’;

export function notifyOwnerOnDashboard() {
wixCrm.notifications.notify(
“Notification body”,
[“Dashboard”],
{
“title”: “Notification Title”,
“actionTitle”: “Click this!”,
“actionTarget”: {“url”: “www.google.com”},
“recipients”: {“role”: “Owner”}
}
);
}

You don’t need the file type at the end of your backend import.

import {notifyOwnerOnDashboard} from 'backend/notifications.jsw';//No
import {notifyOwnerOnDashboard} from 'backend/notifications';//Yes

Plus, you should be putting the notifications in the backend in a js file.

@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.

#corvidissue

Thanks all
Chris Silvester