Connect API not returning notifications

connect-apiconnected-appscustom-notification

I'm using a Connected App. this is subscribed to a custom notification (0ML)

i am using the SF standard API: POST /services/data/v54.0/actions/standard/customNotificationAction

with this payload:

{ "inputs" : [
{ "customNotifTypeId" : "0ML1v000000GmaiGAC", "recipientIds" : ["0051v000004exBLAAY"], "title" : "opportunity Closed!", "body" : "Your High Priority Opportunity has been Closed. 27th 14:23", "targetId" : "0WO3N0000016T3cWAE" } ] }

this works fine, i get status code 200, and i also see the notification in salesforce itself in the console, but when i use this API: GET /services/data/v49.0/connect/notifications i get an empty array

Other places on the internet mention that

The API uses the context of the requesting connected app and returns notifications for the appropriate types.

but I do not understand what this means.

Best Answer

Per the documentation ,

When the context user makes a GET request, the API returns the context user’s notifications. The API uses the context of the requesting connected app and returns notifications for the appropriate types.

If a connected app makes a GET request, the API returns only custom notifications for the types that the connected app subscribes to with org-level settings applied. For example, if an admin disabled a notification type for the app, the API doesn’t return notifications for that type. If a third party (not a connected app) makes a GET request, the API returns only custom notifications for the types that are enabled for desktop.

Make sure your connected App is subscribed to related custom notifications under Mobile App Settings as mentioned in doc. Workbench is not an officially supported tool so after the custom notification is triggered, you can try to make GET with the below snippet in Dev console

Http h = new Http();
HttpRequest webReq = new HttpRequest();
webReq.setMethod('GET');
webReq.setHeader('Authorization','Bearer '+UserInfo.getSessionId());
// replace endpoint url
webReq.setEndpoint('https://cti712-dev-ed.my.salesforce.com/services/data/v52.0/connect/notifications');
HttpResponse res = h.send(webReq);
System.debug(' ------ '+res.getbody());



|DEBUG| ------ {"notifications":[{"additionalData":null,"communityId":"all","communityName":null,"count":1,"id":"5b710ed54e7acd9dbd11007b0b72da6d","image":"https://cti712-dev-ed.my.salesforce.com/img/notificationsEmail/custom_notification.png","lastModified":"2022-03-08T12:20:21.050Z","messageBody":"heyyyy","messageTitle":"heyyyy","mostR
Related Topic