Websocket using Notifications 2.0 not getting any events/alarms

Platform info:

I’m writing an application in C# that uses the Notifications API 2.0. I have the role ROLE_NOTIFICATION_2_ADMIN against my user. I’m also using POSTMAN to test these requests.

I’m creating a subscription (POST /notification2/subscriptions) that subscribes to all APIs & has no filters or fragmentsToCopy as I want to narrow it down later on.

{
    "context": "mo",
    "subscription": "{{SubscriptionName}}",
    "source": {
        "id": "{{managedObjectId}}"
    },
    "subscriptionFilter": {
        "apis": [ "*" ]
    },
    "nonPersistent": false
}

After that I creation a Token (POST /notification2/token)

{
  "subscriber": "UniqueNotifications",
  "subscription": "{{SubscriptionName}}",
  "expiresInMinutes": 1440,
  "type": "notification",
  "signed": true,
  "shared": false,
  "nonPersistent": false
}

Once I get the token from the response, I connect to the Websocket: wss://XYZ.machines.cloud/notification2/consumer/?token={{token}}&consumer=postman

I have have extras like a heartbeat which keeps the connection alive & not just the normal 5 mins of inactivity. On close, it unsubscribes & deletes the subscription etc.

Ignoring the c# code for the time being, I’m using POSTMAN. I’m getting a connected:

I’ve also created a simulator for the position / events:

I’ve even tried via POSTMAN to create events & alarms

eg:
POST /event/events

{
  "source": {
    "id": "{{managedObjectId}}"
  },
  "type": "c8y_Sharry",
  "text": "Sharry event testing",
  "time": "2024-11-13T11:05:27.845Z"
}

POST /alarm/alarms

{
  "source": {
    "id": "{{managedObjectId}}"
  },
  "type": "c8y_Sharry",
  "text": "Sharry WARNING testing",
  "severity": "WARNING",
  "time": "2024-11-13T10:05:27.845Z",
  "status": "ACTIVE"
}

No matter what I do whether enabling the simulator or sending events via the API on POSTMAN, nothing appears in the application console or POSTMAN console.

Any help greatly appreciated.

Sharry

It all looks fine but you have a lot of optional stuff there with it’s default values:

For example:

{
  "subscriber": "UniqueNotifications",
  "subscription": "{{SubscriptionName}}",
  "expiresInMinutes": 1440,
  "type": "notification",
  "signed": true,
  "shared": false,
  "nonPersistent": false
}

could be just this:

{
  "subscriber": "UniqueNotifications",
  "subscription": "{{SubscriptionName}}"
}

For the WebSocket URL you can ignore the consumer as “postman” is not unique at all.
But in general it should also work this way. Are you sure postman does not receive anything? I guess the managedObjectID is the same? Could it be that there other subscribers with the same name?

Also make sure to unsubscribe with a valid token and the subscriber you have used before.

1 Like

Thanks Stefan, think I was getting subscriber & subscription mixed up on the creation/token creation.

1 Like