11. POST Resource notifiers

11. POST Resource notifiers

Setting up the notifications

NAO Cloud can be configured to send a POST request whenever resources of a certain type are modified, or triggered (applicable for alerts only). Modification includes creation, update and deletion of a resource of those types.

The Resource notifiers can be accessed via the Overview/Actions/Resource notifiers menu of a NAO Cloud site. On this page you will be able to create new notifiers, as well as list all existing notifiers for the current site.

When creating a notifier, along with the resource types that will trigger the request and the events that should trigger requests you will be able to set the URL to which the POST request will be made, as well as additional custom parameters that should be sent along with the notification parameters.

Receiving the POST request

The POST request that will be sent will have the following format :

POST post_url HTTP/1.1
Content-Type: application/json

{
  "resource_id": 1,
  "resource_type": "Region",
  "action": "Update",
  "time": "2016-11-07T11:00:00Z"
}

Any custom parameter that was set in the notifier will be added to the previous parameters.

NAO Cloud expects in return a 200 response code. If it receives a different response code, the notification will be marked as not sent and will be stored for future sending.

Accessing and re-sending failed notifications

Notifications that couldn’t be sent can be accessed in two different ways, on the NAO Cloud site or using the NAO Cloud API.

Pending notifications can be accessed by accessing a notifier’s configuration page. Note that in the Resource Notifiers index page a badge will appear to indicate the number of notifications that could not be sent. On the notifier’s page, a table of all unsent notifications and their informations can be seen at the bottom. From there you can either delete the notifications or re-send them.

Using the API, there are several end-points that can be used to retrieve informations of the notifier and its pending notifications. First, a notifier can be accessed using the following endpoint:

GET /api/v2/sites/{site_id}/notifiers/{id}

Along with the notifier’s attributes such as the post_url and post_params, there is a nb_pending_notifications attribute that indicates the number of pending notifications. The notifications can then be accessed using the following endpoint:

GET /api/v2/sites/{site_id}/notifiers/{notifier_id}/notifications

Each notification can then be individually accessed using their endpoint

GET /api/v2/sites/{site_id}/notifiers/{notifier_id}/notifications/{id}

To mark the notification as read and remove it from the list, you then need to destroy it using its DELETE endpoint :

DELETE /api/v2/sites/{site_id}/notifiers/{notifier_id}/notifications/{id}
    • Related Articles

    • 10. Cross-Origin Resource Sharing

      The API supports Cross Origin Resource Sharing (CORS) for AJAX requests from any origin.
    • 8. Storage Related Resources

      Consider a situation when you need to create a resource that references a file (e.g: an image). The file needs to be uploaded before resource creation and after requested to get the credentials allowing you to upload to the storage service. The steps ...
    • 8. Storage Related Resources

      Consider a situation when you need to create a resource that references a file (e.g: an image). The file needs to be uploaded before resource creation and after requested to get the credentials allowing you to upload to the storage service. The steps ...
    • 5. Creating, Updating and Deleting Resources

      NAO Cloud allows resources of a given type to be created and allows some existing resources to be modified or deleted. A request either succeeds or fails atomically (in a single “transaction”). No partial updates are allowed. Creating Resources A ...
    • Tags commissioning

      1. Adding a tag A tag can be created by sending a POST request to /api/v2/sites/{SITE_ID}/nao_trackables. The SITE_ID will be provided by Pole Star after the deployment of the site. NAO Cloud REST API – Add a tag If SITE_ID is 12061 and the ...