Create CloudHub Notifications Using Rest API 

Author Name: Rohit Wadne

This blog will explain to you how you can generate CloudHub notifications using CloudHub REST API. Due to MFA being enabled on your AnyPoint platform, you can’t use CloudHub to create a notification connector. In this blog, we will use CloudHub REST API for creating notifications.

Here is the trick.

Steps:
  1. The first step is that we need to create a connected app and provide the Runtime Manager permission. Copy the client ID and client secret for the connected app.
  1. Go to the Runtime Manager Alerts tab for the creation of alerts.
  1. Click on the plus icon on the top right to create an alert. Then do the necessary configuration for your alert. Further, add the emails recipient list and click on the submit button. Below is the sample configuration.
  1. To create notifications, you need to get an access token which will pass as a bearer token. To receive token you need to call this Endpoint. 

Curl command:

curl --location --request POST 'https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=connected app client id \
--data-urlencode 'client_secret=connected app client id' \
--data-urlencode 'grant_type=client_credentials'

Here is the response:

{
    "access_token": "9270a0e4-6344-49f4-96af-6ef605a158a5",
    "expires_in": 3600,
    "token_type": "bearer"
}
  1. After every 3600 seconds, the token will expire and you have to call this Endpoint to get the access token.
  1. After this, you need to make a Post request for generating a notification. Fields that are to be passed post body are :
  • Domain: This is the application name deployed in CloudHub.
  • Message: This is the message we will get in the notification.
  • TransactionId: This is a unique ID for each transaction (e.g. correlation ID) (Non-Mandatory).
  • Priority: This is the priority for notification (Non-Mandatory).
  • CustomerProperties: These are the properties that we have stated in the AnyPoint platform. You can modify the properties as you want. You have to set the same properties in AnyPoint platform alerts (Non-Mandatory).
curl --location --request POST 'https://anypoint.mulesoft.com/cloudhub/api/notifications' \
--header 'X-ANYPNT-ENV-ID: Environment Id' \
--header 'Authorization: Bearer access-token' \
--header 'Content-Type: application/json' \
--data-raw '{
  "domain": "application name deployed in cloudhub",
  "message": "This is the message we will get at notification",
  "transactionId": "correlation id", 
  "priority": "INFO",
  "customProperties": {
    "api-name": "Application name deployed in cloudhub",
    "code": error code,
    "ErrorReason": "The error Type",
    "timestamp": "time stamp ",
    "correlationId": "id "
  }
}'
  1. After you initiate the call, you will receive the notification in your mail.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.