Skip to content

Notification Service – Samples

Sending an e-mail notification with simple content

  • Use API endpoint - POST /api/notification/v3/publisher/messages

Multiple e-mail recipients can be provided as semicolon-separated in the recipientTo field.

Sample Request payload:

1
2
3
4
5
6
7
8
9
{
    "body":
        {
            "message":"E-mail message content"
        },
    "recipientsTo":"xxxxxx.xxxxxx@siemens.com;yyyyyy.yyyyyy@mindsphere.io",
    "from":"sender-name",
    "subject":"E-mail subject"
}

Sending an e-mail notification using template

To send e-mails using templates, call the APIs below in the order listed.

Creating a recipient with e-mail details

  • Use API Endpoint - POST /api/notification/v3/recipient/

For providing valid input for the addresstypeid, refer to the /recipient/addresstype of the Notification Service API Specification.

Sample Request:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  "recipientname" : "XXXXXXXX XXXXXXXX",
  "recipientdetail" : [ {
    "address" : "xxxxxx.xxxxxx@siemens.com",
    "addresstypeid" : 2
  },
  {
    "address" : "personalmail@gmail.com",
    "addresstypeid" : 1
  } ]
}

Sample Response:

1
806

You receive the generated recipientID in response. Store this information as reference for the following API calls.

Creating a message template with content

  • Use API Endpoint - POST /api/notification/v3/template/

Follow the API guidelines for this endpoint for detailed information on the request structure and creating placeholders. For providing valid input for the commChannelId, refer to the /communicationchannel/ of the Notification Service API Specification.

Sample template:

1
2
3
<html xmlns:th="http://www.thymeleaf.org" th:inline="text" th:remove="tag">
    Hello [[${name}]],Please click the url more more details : <a th:href="${actualurl}">[[${url}]]</a>
</html>

Here, 'name' and 'url' are the defined placeholders.

Sample response:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
    "templatesetId": 111,
    "templatesetName": "TestTemplateForEmail",
    "templateList": [
        {
            "templateId": 412,
            "commChannelId": 1,
            "commChannelName": "Email"
        }
    ]
}

Store the values of templatesetId and templateId as reference for the following API calls.

Creating a category using the template and recipients

  • Use API Endpoint - POST /api/notification/v3/communicationcategories/

Sample Request:

In this request sends the recipientID, templatesetId and templateId stored in the previous steps.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
{
    "msgCategoryName": "category Name",
    "subject": "Any subject",
    "priority":1,
    "from":"sender-name",
    "recipients":[
        {
            "recipientId":806,
            "position":"TO"
        }
    ],
    "templates":[
        {
            "templateId":412,
            "templatesetId":111,
            "commChannelName":"Email"
        }
    ]
}

Sample Response:

1
    642

You receive the generated categoryID in response. Store this information as reference for the following API call.

Triggering the notification

  • Use API endpoint - POST /api/notification/v3/publisher/messages

The request must contain the placeholders defined in your template and their respective values as well as the categoryId stored in the previous step. In addition to the recipients subscribed to the category, other e-mail recipients can added in the recipientTo field separated by semicolons.

Sample Request:

1
2
3
4
5
6
7
8
{
  "body" : {
    "placeholderkey1" : "placeholder value1",
    "placeholderkey2" : "placeholder value2",
        },
    "recipientsTo" : "xxxxxxx.xxxxxx@siemens.com",
    "messageCategoryId" :642
}

Sending push notifications with a template

Notification services provides the functionality of sending push notifications to mobile devices. To send push notifications using a template, call the APIs below in the order listed.

Creating a recipient with push notification details

  • Use API Endpoint - POST /api/notification/v3/recipient/

For providing valid input for the addresstypeid, refer to the /recipient/addresstype of the Notification Service API Specification. The following information must be provided in the request:

  • serverApiKey
    This key is stored on the app server that gives the app server authorized access to Google services. It is unique to every application.
  • appId
    An ID issued by the GCM connection servers to the client app that allows it to receive messages. This is specific to every device and the application installed.
  • applicationName
    Name of the application sending the notifications.

Sample Request:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  "recipientname" : "PushNotificationTest",
  "recipientdetail" : [{
    "address" : {
            "appId":"XXXXXXXXXXXXXXXXXXXXX",
            "serverApiKey":"XXXXXXXXXXXXXXXXX",
            "applicationName":"App Name 1"
    },
    "addresstypeid" : 7
  }]
}

Sample Response:

1
806

You receive the generated recipientID. Store this information as reference for the following API calls.

Creating a push notification template with content

  • Use API Endpoint - POST /api/notification/v3/template/

Follow the API guidelines for this endpoint for detailed information on the request structure and creating placeholders. For providing valid input for the commChannelId, refer to the /communicationchannel/ of the Notification Service API Specification.

Sample template:

1
2
3
<html xmlns:th="http://www.thymeleaf.org" th:inline="text" th:remove="tag">
    Hello [[${name}]],Please click the url more more details : <a th:href="${actualurl}">[[${url}]]</a>
</html>

Here, 'name' and 'url' are the defined placeholders.

Sample response:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
    "templatesetId": 436,
    "templatesetName": "TestTemplateForPushNotification12",
    "templateList": [
        {
            "templateId": 468,
            "commChannelId": 3,
            "commChannelName": "Push Notification"
        }
    ]
}

Store the values of templatesetId and templateId as reference for the following API calls.

Creating category using the template and recipients

  • Use API Endpoint - POST /api/notification/v3/communicationcategories/

Sample Request:

Here, the information from the response of above API calls like recipient ID, templatesetId and templateId will be sent in request.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
{
    "msgCategoryName": "category Name",
    "subject": "Any subject",
    "priority":1,
    "from":"sender-name",
    "recipients":[
        {
            "recipientId":806,
            "position":"TO"
        }
    ] ,
    "templates":[
        {
            "templateId":468,
            "templatesetId":436,
            "commChannelName":"Push Notification"
        }
    ]
}

Sample Response:

1
    642

The value of generated category ID will be sent in response. This information needs to be stored as reference for the following API calls.

Triggering the notification

  • Use API endpoint - POST /api/notification/v3/publisher/messages

The request must contain the placeholders defined in your template and their respective values as well as the categoryId stored in the previous step.

Sample Request:

1
2
3
4
5
6
7
8
{
    "body" :
    {
        "placeholderkey1" : "placeholder value1",
        "placeholderkey2" : "placeholder value2",
    },
    "messageCategoryId":642
}

For further details refer to the Notification Service API Specification.

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.