/event-notifications-java-admin-sdk

Java server SDK for IBM Cloud Event Notifications service

Primary LanguageJavaApache License 2.0Apache-2.0

Build Status semantic-release

Java server SDK for IBM Cloud Event Notifications service Version 0.6.0

Java client library to interact with various IBM Cloud Event Notifications Service.

Table of Contents

Overview

The IBM Cloud Event Notifications Service Java SDK allows developers to programmatically interact with Event Notifications service in IBM cloud.

Service Name Artifact Coordinates
Event Notifications Service com.ibm.cloud:event-notifications:0.6.0

Prerequisites

  • An IBM Cloud account.
  • An Event Notifications Instance
  • An IAM API key to allow the SDK to access your account. Create one here.
  • Java 11 or above.

Installation

The current version of this SDK is: 0.6.0

Each service's artifact coordinates are listed in the table above.

The project artifacts are published on the public Maven Central artifact repository. This is the default public repository used by maven when searching for dependencies. To use this repository within a gradle build, please see this link.

To use the Event Notifications Java SDK, define a dependency that contains the artifact coordinates (group id, artifact id and version) for the service, like this:

Maven

<dependency>
    <groupId>com.ibm.cloud</groupId>
    <artifactId>event-notifications</artifactId>
    <version>0.6.0</version>
</dependency>

Gradle

compile 'com.ibm.cloud:event-notifications:0.6.0'

Using the SDK

For general SDK usage information, please see this link

Initialize SDK

Initialize the sdk to connect with your Event Notifications service instance.

import com.ibm.cloud.eventnotifications.event_notifications.v1.EventNotifications;

EventNotifications eventNotificationsService = EventNotifications.newInstance();
eventNotificationsService.setServiceUrl("https://" + region + ".event-notifications.cloud.ibm.com/event-notifications");

To configure service URL for Private Endpoint

If you enabled service endpoints in your account, you can send API requests over the IBM Cloud private network. In the initialisation, the base endpoint URLs of the IAM(authenticator) & Event Notification(service) should be modified to point to private endpoints.

  1. Setting client options programmatically
Authenticator authenticator = new IamAuthenticator.Builder()
        .apikey("<iam-api-key>")
        .url("https://private.iam.cloud.ibm.com")
        .build();

EventNotifications eventNotificationsService = EventNotifications.newInstance();
eventNotificationsService.setServiceUrl("https://private." + region + ".event-notifications.cloud.ibm.com/event-notifications");
  1. Using external configuration properties
   EVENT_NOTIFICATIONS_AUTH_URL = https://private.iam.cloud.ibm.com/identity/token
  • region : Region of the Event Notifications Instance

Using the SDK

SDK Methods to consume

Source

Create Source

CreateSourcesOptions createSourcesOptions = new CreateSourcesOptions.Builder()
              .instanceId(<instanceId>)
              .name(<source-name>)
              .description(<source-description>)
              .enabled(true)
              .build();

Response<SourceResponse> response = eventNotificationsService.createSources(createSourcesOptions).execute();
SourceResponse sourceResponse = response.getResult();

List Sources

ListSourcesOptions listSourcesOptions = new ListSourcesOptions.Builder()
        .instanceId(<instanceId>)
        .build();

Response<SourceList> response = eventNotificationsService.listSources(listSourcesOptions).execute();
SourceList sourceList = response.getResult();
System.out.println(sourceList);

Get Source

GetSourceOptions getSourceOptions = new GetSourceOptions.Builder()
        .instanceId(<instanceId>)
        .id(<sourceId>)
        .build();

Response<Source> response = eventNotificationsService.getSource(getSourceOptions).execute();
Source source = response.getResult();
System.out.println(source);

Update Source

UpdateSourceOptions updateSourceOptions = new UpdateSourceOptions.Builder()
        .instanceId(<instanceId>)
        .id(<sourceId>)
        .name(<source-name>)
        .description(<source-description>)
        .enabled(true)
        .build();

Response<Source> response = eventNotificationsService.updateSource(updateSourceOptions).execute();
Source source = response.getResult();

Delete Source

 DeleteSourceOptions deleteSourceOptions = new DeleteSourceOptions.Builder()
        .instanceId(<instanceId>)
        .id(<sourceId>)
        .build();
Response<Void> response = eventNotificationsService.deleteSource(deleteSourceOptions).execute();

Topics

Create Topic

Rules rulesModel = new Rules.Builder()
        .enabled(true)
        .eventTypeFilter("$.notification_event_info.event_type == 'cert_manager'")
        .notificationFilter("$.notification.findings[0].severity == 'MODERATE'")
        .build();

TopicUpdateSourcesItem topicUpdateSourcesItemModel = new TopicUpdateSourcesItem.Builder()
        .id(<sourceId>)
        .rules(new java.util.ArrayList<Rules>(java.util.Arrays.asList(rulesModel)))
        .build();

CreateTopicOptions createTopicOptions = new CreateTopicOptions.Builder()
        .instanceId(<instanceId>)
        .name(<topicName>)
        .description("This topic is used for routing all compliance related notifications to the appropriate destinations")
        .sources(new java.util.ArrayList<TopicUpdateSourcesItem>(java.util.Arrays.asList(topicUpdateSourcesItemModel)))
        .build();

Response<TopicResponse> response = eventNotificationsService.createTopic(createTopicOptions).execute();
TopicResponse topicResponse = response.getResult();

System.out.println(topicResponse);

List Topics

ListTopicsOptions listTopicsOptions = new ListTopicsOptions.Builder()
        .instanceId(<instanceId>)
        .build();

Response<TopicList> response = eventNotificationsService.listTopics(listTopicsOptions).execute();
TopicList topicList = response.getResult();
System.out.println(topicList);

Get Topic

GetTopicOptions getTopicOptions = new GetTopicOptions.Builder()
        .instanceId(<instanceId>)
        .id(<topicId>)
        .build();

Response<Topic> response = eventNotificationsService.getTopic(getTopicOptions).execute();
Topic topic = response.getResult();
System.out.println(topic);

Update Topic

Rules rulesModel = new Rules.Builder()
        .enabled(true)
        .eventTypeFilter("$.notification_event_info.event_type == 'cert_manager'")
        .notificationFilter("$.notification.findings[0].severity == 'MODERATE'")
        .build();

TopicUpdateSourcesItem topicUpdateSourcesItemModel = new TopicUpdateSourcesItem.Builder()
        .id(<sourceId>)
        .rules(new java.util.ArrayList<Rules>(java.util.Arrays.asList(rulesModel)))
        .build();

String description = "Updated Topic for GCM notifications";
String name = "Updated Admin Topic Compliance";

ReplaceTopicOptions replaceTopicOptions = new ReplaceTopicOptions.Builder()
        .instanceId(<instanceId>)
        .id(<topicId>)
        .name(<name>)
        .description(<description>)
        .sources(new java.util.ArrayList<TopicUpdateSourcesItem>(java.util.Arrays.asList(topicUpdateSourcesItemModel)))
        .build();

Response<Topic> response = eventNotificationsService.replaceTopic(replaceTopicOptions).execute();
Topic topic = response.getResult();
System.out.println(topic);

Delete Topic

DeleteTopicOptions deleteTopicOptions = new DeleteTopicOptions.Builder()
        .instanceId(<instanceId>)
        .id(<topicId>)
        .build();

Response<Void> response = eventNotificationsService.deleteTopic(deleteTopicOptions).execute();

Destinations

Create Destination

DestinationConfigParamsWebhookDestinationConfig destinationConfigParamsModel = new DestinationConfigParamsWebhookDestinationConfig.Builder()
        .url(<destination-config-url>)
        .verb(<destination-config-verb>)
        .customHeaders(new java.util.HashMap<String, String>() { { put(<header-key>, <header-value>); } })
        .sensitiveHeaders(new java.util.ArrayList<String>(java.util.Arrays.asList(<header-key>)))
        .build();

DestinationConfig destinationConfigModel = new DestinationConfig.Builder()
        .params(destinationConfigParamsModel)
        .build();

CreateDestinationOptions createDestinationOptions = new CreateDestinationOptions.Builder()
        .instanceId(<instanceId>)
        .name(<name>)
        .type(<typeVal>)
        .description(<description>)
        .config(destinationConfigModel)
        .build();

Response<DestinationResponse> response = eventNotificationsService.createDestination(createDestinationOptions).execute();
DestinationResponse destinationResponse = response.getResult();
System.out.println(destinationResponse);

Among the supported destinations, if you need to create Push Notification destinations, you have the additional option of choosing a destination of production type or pre-production type. Set pre_prod boolean parameter to true to configure destination as pre-production destination else set the value as false. Supported destinations are Android, iOS, Chrome, Firefox and Safari.

List Destinations

ListDestinationsOptions listDestinationsOptions = new ListDestinationsOptions.Builder()
        .instanceId(<instanceId>)
        .build();

Response<DestinationList> response = eventNotificationsService.listDestinations(listDestinationsOptions).execute();
DestinationList destinationList = response.getResult();
System.out.println(destinationList);

Get Destination

GetDestinationOptions getDestinationOptions = new GetDestinationOptions.Builder()
        .instanceId(<instanceId>)
        .id(<destinationId>)
        .build();

Response<Destination> response = eventNotificationsService.getDestination(getDestinationOptions).execute();
Destination destination = response.getResult();
System.out.println(destination);

Update Destination

DestinationConfigParamsWebhookDestinationConfig destinationConfigParamsModel = new DestinationConfigParamsWebhookDestinationConfig.Builder()
        .url(<destination-config-update-url>)
        .verb(<destination-config-update-verb>)
        .sensitiveHeaders(new java.util.ArrayList<String>(java.util.Arrays.asList(<header-key>)))
        .build();

DestinationConfig destinationConfigModel = new DestinationConfig.Builder()
        .params(destinationConfigParamsModel)
        .build();

UpdateDestinationOptions updateDestinationOptions = new UpdateDestinationOptions.Builder()
        .instanceId(<instanceId>)
        .id(<destinationId>)
        .name(<name>)
        .description(<description>)
        .config(destinationConfigModel)
        .build();

Response<Destination> response = eventNotificationsService.updateDestination(updateDestinationOptions).execute();
Destination destination = response.getResult();
System.out.println(destination);

Delete Destination

DeleteDestinationOptions deleteDestinationOptions = new DeleteDestinationOptions.Builder()
        .instanceId(<instanceId>)
        .id(<destinationId>)
        .build();

Response<Void> response = eventNotificationsService.deleteDestination(deleteDestinationOptions).execute();

Test Destination

This functionality allows you to test a destination. The feature simplifies the process of verifying whether a destination is functioning correctly. Currently, this functionality supports following destinations:

  1. Slack
  2. PagerDuty
  3. ServiceNow
  4. Microsoft® Teams
  5. IBM Cloud Code Engine
  6. IBM Cloud Functions
  7. IBM Cloud Object Storage
TestDestinationOptions testDestinationOptionsModel = new TestDestinationOptions.Builder()
        .instanceId(<instaceID>) // Event notifications service instance GUID
        .id(<destinationId>) // Event notifications service instance Destination ID
        .build();

Response<TestDestinationResponse> response = eventNotificationsService.testDestination(testDestinationOptionsModel).execute();

Once the test is completed, you will be presented with the results. These results will typically include:

  • Status: Whether the test is successful or failed
  • Response Code: If test fails, then the response code sent from the end destination client is returned
  • Response Message: If test fails, then the response message sent from the end destination client is returned

Custom Domain Name Verification

After creation of the custom email destination with your domain name, make sure its validated for the right ownership. This can be done with SPF and DKIM verification.

  • Sender Policy Framework (SPF), which is used to authenticate the sender of an email. SPF specifies the mail servers that are allowed to send email for your domain.
  • DomainKeys Identified Mail (DKIM), which allows an organization to take responsibility for transmitting a message by signing it. DKIM allows the receiver to check the email that claimed to have come from a specific domain, is authorized by the owner of that domain.
UpdateVerifyDestinationOptions updateVerifyDestinationOptionsModel = new UpdateVerifyDestinationOptions.Builder()
        .instanceId(<instanceId>)
        .id(<destinationId>)
        .type(<verificationType>)
        .build();

Response<VerificationResponse> verificationResponse = service.updateVerifyDestination(updateVerifyDestinationOptionsModel).execute();
VerificationResponse responseObj = verificationResponse.getResult();

Templates

Template is a pre-defined layout, that may include content like images, text and dynamic content based on event. Rather than creating a new content from scratch each time, you can use a template as a base and configure them in subscription. supports the following templates:

  • Custom Email notification
  • Custom Email invitation

Create Template

Custom Email Template

TemplateConfigOneOfEmailTemplateConfig templateConfig = new TemplateConfigOneOfEmailTemplateConfig.Builder()
        .body("base 64 encoded html content")
        .subject("Hi this is invitation for invitation message")
        .build();

CreateTemplateOptions createTemplateInvitationOptions = new CreateTemplateOptions.Builder()
        .instanceId(<instanceId>)
        .name(<name>)
        .description(<description>)
        .type(<template-type>)
        .params(templateConfig)
        .build();

Response<TemplateResponse> invitationResponse = eventNotificationsService.createTemplate(createTemplateInvitationOptions).execute();

For custom email supported template type values: smtp_custom.invitation, smtp_custom.notification

Slack Template

TemplateConfigOneOfSlackTemplateConfig slackTemplateConfig = new TemplateConfigOneOfSlackTemplateConfig.Builder()
        .body("base 64 encoded html content")
        .subject("Hi this is invitation for invitation message")
        .build();

CreateTemplateOptions createTemplateInvitationOptions = new CreateTemplateOptions.Builder()
        .instanceId(<instanceId>)
        .name(<name>)
        .description(<description>)
        .type(<template-type>)
        .params(templateConfig)
        .build();

Response<TemplateResponse> invitationResponse = eventNotificationsService.createTemplate(createTemplateInvitationOptions).execute();

For slack template supported template type value: slack.notification

List Templates

ListTemplatesOptions listTemplatesOptions = new ListTemplatesOptions.Builder()
        .instanceId(<instanceId>)
        .limit(<limit>)
        .offset(<offset>)
        .search(<search>)
        .build();

Response<TemplateList> response = eventNotificationsService.listTemplates(listTemplatesOptions).execute();

Get Template

GetTemplateOptions getTemplateOptions = new GetTemplateOptions.Builder()
        .instanceId(<instanceId>)
        .id(<templateId>)
        .build();

Response<Template> response = eventNotificationsService.getTemplate(getTemplateOptions).execute();

Update Template

TemplateConfig templateConfig = new TemplateConfig.Builder()
              .body("base 64 encoded html content")
              .subject("Hi this is invitation for invitation message")
              .build();

ReplaceTemplateOptions updateTemplateInvitationOptions = new ReplaceTemplateOptions.Builder()
        .instanceId(<instanceId>)
        .id(<templateId>)
        .name(<name>)
        .description(<description>)
        .type(<templateType>)
        .params(templateConfig)
        .build();

Response<Template> invitationResponse = eventNotificationsService.replaceTemplate(replaceTemplateInvitationOptions).execute();

Delete Template

DeleteTemplateOptions deleteTemplateOptions = new DeleteTemplateOptions.Builder()
                .instanceId(<instanceId>)
                .id(<templateId>)
                .build();

Response<Void> response = eventNotificationsService.deleteTemplate(deleteTemplateOptions).execute();

Push Destination APIs

Create Destination tag subscription

CreateTagsSubscriptionOptions createTagsSubscriptionOptionsModel = new CreateTagsSubscriptionOptions.Builder()
        .instanceId(<instanceId>) // Event notifications service instance GUID
        .id(<destination-id>)     // Event notifications service instance Destination ID
        .deviceId(<device-id>)    // Event notifications service device ID
        .tagName(<tag-name>)      // Event notifications service tag name
        .build();

// Invoke createTagsSubscription() with a valid options model and verify the result
Response<DestinationTagsSubscriptionResponse> response = eventNotificationsService.createTagsSubscription(createTagsSubscriptionOptionsModel).execute();
DestinationTagsSubscriptionResponse destinationTagsSubscription = response.getResult();
System.out.println(destinationTagsSubscription);

List Destination tag subscription

ListTagsSubscriptionOptions listTagsSubscriptionOptionsModel = new ListTagsSubscriptionOptions.Builder()
        .instanceId(<instanceId>)  // Event notifications service instance GUID
        .id(<destination-id>)      // Event notifications service instance Destination ID// Event notifications service user ID
        .build();

// Invoke listTagsSubscription() with a valid options model and verify the result
Response<TagsSubscriptionList> response = eventNotificationsService.listTagsSubscription(listTagsSubscriptionOptionsModel).execute();
TagsSubscriptionList tagsSubscriptionList = response.getResult();
System.out.println(tagsSubscriptionList);

Delete Destination device tag subscription

DeleteTagsSubscriptionOptions deleteTagsSubscriptionOptionsModel = new DeleteTagsSubscriptionOptions.Builder()
        .instanceId(<instanceId>)  // Event notifications service instance GUID
        .id(<destination-id>)      // Event notifications service instance Destination ID
        .deviceId(<device-id>)     // Event notifications service device ID
        .tagName(<tag-name>)       // Event notifications service tag name
        .build();

// Invoke deleteTagsSubscription() with a valid options model and verify the result
Response<Void> response = eventNotificationsService.deleteTagsSubscription(deleteTagsSubscriptionOptionsModel).execute();
System.out.println(response);

Subscriptions

Create Subscription

SubscriptionCreateAttributesWebhookAttributes subscriptionCreateWebAttributesModel = new SubscriptionCreateAttributesWebhookAttributes.Builder()
    .signingEnabled(false).build();

CreateSubscriptionOptions createSubscriptionOptions = new CreateSubscriptionOptions.Builder()
    .instanceId(<instanceId>)
    .name(<name>)
    .destinationId(<destinationId>)
    .topicId(<topicId>)
    .attributes(subscriptionCreateWebAttributesModel)
    .description(<description>)
    .build();

Response<Subscription> response = eventNotificationsService.createSubscription(createSubscriptionOptions).execute();
Subscription subscription = response.getResult();
System.out.println(subscription);

List Subscriptions

ListSubscriptionsOptions listSubscriptionsOptions = new ListSubscriptionsOptions.Builder()
    .instanceId(<instanceId>)
    .build();

Response<SubscriptionList> response = eventNotificationsService.listSubscriptions(listSubscriptionsOptions).execute();
SubscriptionList subscriptionList = response.getResult();
System.out.println(subscriptionList);

Get Subscription

 GetSubscriptionOptions getSubscriptionOptions = new GetSubscriptionOptions.Builder()
        .instanceId(<instanceId>)
        .id(<subscriptionId>)
        .build();

Response<Subscription> response = eventNotificationsService.getSubscription(getSubscriptionOptions).execute();
Subscription subscription = response.getResult();
System.out.println(subscription);

Update Subscription

SubscriptionUpdateAttributesWebhookAttributes subscriptionUpdateWebAttributesModel = new SubscriptionUpdateAttributesWebhookAttributes.Builder()
        .signingEnabled(true)
        .build();

UpdateSubscriptionOptions updateSubscriptionOptions = new UpdateSubscriptionOptions.Builder()
        .instanceId(<instanceId>)
        .id(<subscriptionId>)
        .name(<name>)
        .description(<description>)
        .attributes(subscriptionUpdateWebAttributesModel)
        .build();

Response<Subscription> response = eventNotificationsService.updateSubscription(updateSubscriptionOptions).execute();
Subscription subscription = response.getResult();
System.out.println(subscription);

Delete Subscription

DeleteSubscriptionOptions deleteSubscriptionOptions = new DeleteSubscriptionOptions.Builder()
    .instanceId(<instanceId>)
    .id(<subscriptionId>)
    .build();

Response<Void> response = eventNotificationsService.deleteSubscription(deleteSubscriptionOptions).execute();

Integration

Create Integration

IntegrationCreateMetadata metadata = new IntegrationCreateMetadata.Builder()
        .endpoint(cosEndPoint)
        .crn(cosInstanceCRN)
        .bucketName(cosBucketName)
        .build();

        CreateIntegrationOptions integrationsOptions = new CreateIntegrationOptions.Builder()
        .instanceId(instanceId)
        .type("collect_failed_events")
        .metadata(metadata)
        .build();
Response<IntegrationCreateResponse> response = service.createIntegration(integrationsOptions).execute();

Get Integration

GetIntegrationOptions integrationsOptions = new GetIntegrationOptions.Builder()
        .instanceId(<instanceId>)
        .id(<integrationId>)
        .build();

Response<IntegrationGetResponse> response = eventNotificationsService.getIntegration(integrationsOptions).execute();

List Integrations

ListIntegrationsOptions integrationsOptions = new ListIntegrationsOptions.Builder()
        .instanceId(<instanceId>)
        .limit(<limit>)
        .offset(<offset>)
        .search(<search>)
        .build();

Response<IntegrationList> response = eventNotificationsService.listIntegrations(integrationsOptions).execute();

Update Integration

For kms/hs-crypto-

IntegrationMetadata metadata = new IntegrationMetadata.Builder()
        .endpoint("<end-point>")
        .crn("<crn>")
        .rootKeyId(<rootKeyId>)
        .build();

ReplaceIntegrationOptions integrationsOptions = new ReplaceIntegrationOptions.Builder()
        .instanceId(<instanceId>)
        .id(<integrationId>)
        .type(<integrationType>)
        .metadata(metadata)
        .build();
        
Response<IntegrationGetResponse> response = eventNotificationsService.replaceIntegration(integrationsOptions).execute();

For Cloud Object Storage-

IntegrationMetadata cosMetadata = new IntegrationMetadata.Builder()
        .endpoint(cosEndPoint)
        .crn(cosInstanceCRN)
        .bucketName(cosBucketName)
        .build();

ReplaceIntegrationOptions cfeIntegrationsOptions = new ReplaceIntegrationOptions.Builder()
        .instanceId(instanceId)
        .id(cosIntegrationID)
        .type("collect_failed_events")
        .metadata(cosMetadata)
        .build();

// Invoke operation
Response<IntegrationGetResponse> cfeResponse = eventNotificationsService.replaceIntegration(cfeIntegrationsOptions).execute();

SMTPConfigurations

Create SMTP Configuration

CreateSmtpConfigurationOptions createSMTPConfigurationOptions = new CreateSmtpConfigurationOptions.Builder()
        .instanceId(<instanceId>)
        .domain(<smtpDomain>)
        .name(<smtpName>)
        .description(<smtpDescription>)
        .build();

Response<SMTPCreateResponse> response = eventNotificationsService.createSmtpConfiguration(createSMTPConfigurationOptions).execute();
SMTPCreateResponse smtpCreateResponse = response.getResult();

Create SMTP User

CreateSmtpUserOptions createSmtpUserOptionsModel = new CreateSmtpUserOptions.Builder()
        .instanceId(<instanceId>)
        .id(<smtpConfigID>)
        .description(<smtpDescription>)
        .build();

Response<SMTPUserResponse> response = eventNotificationsService.createSmtpUser(createSmtpUserOptionsModel).execute();
SMTPUserResponse responseObj = response.getResult();

Get SMTP Configuration

GetSmtpConfigurationOptions getSmtpConfigurationOptionsModel = new GetSmtpConfigurationOptions.Builder()
        .instanceId(<instanceId>)
        .id(<smtpConfigID>)
        .build();

Response<SMTPConfiguration> response = eventNotificationsService.getSmtpConfiguration(getSmtpConfigurationOptionsModel).execute();
SMTPConfiguration responseObj = response.getResult();

Get SMTP User

GetSmtpConfigurationOptions getSmtpConfigurationOptionsModel = new GetSmtpConfigurationOptions.Builder()
        .instanceId(<instanceId>)
        .id(<smtpConfigID>)
        .build();

Response<SMTPConfiguration> response = eventNotificationsService.getSmtpConfiguration(getSmtpConfigurationOptionsModel).execute();
SMTPConfiguration responseObj = response.getResult();

Get SMTP Allowed Ips

GetSmtpAllowedIpsOptions getSmtpAllowedIpsOptionsModel = new GetSmtpAllowedIpsOptions.Builder()
        .instanceId(<instanceId>)
        .id(<smtpConfigID>)
        .build();

Response<SMTPAllowedIPs> response = eventNotificationsService.getSmtpAllowedIps(getSmtpAllowedIpsOptionsModel).execute();
SMTPAllowedIPs responseObj = response.getResult();

List SMTP Configurations

GetSmtpAllowedIpsOptions getSmtpAllowedIpsOptionsModel = new GetSmtpAllowedIpsOptions.Builder()
        .instanceId(<instanceId>)
        .id(<smtpConfigID>)
        .build();

Response<SMTPAllowedIPs> response = eventNotificationsService.getSmtpAllowedIps(getSmtpAllowedIpsOptionsModel).execute();
SMTPAllowedIPs responseObj = response.getResult();

List SMTP Users

ListSmtpUsersOptions listSmtpUsersOptionsModel = new ListSmtpUsersOptions.Builder()
        .instanceId(<instanceId>)
        .id(<smtpConfigID>)
        .limit(limit)
        .offset(offset)
        .search(search)
        .build();

// Invoke listSmtpUsers() with a valid options model and verify the result
Response<SMTPUsersList> response = eventNotificationsService.listSmtpUsers(listSmtpUsersOptionsModel).execute();
SMTPUsersList smtpUsersList = response.getResult();

Update SMTP Configuration

UpdateSmtpConfigurationOptions updateSmtpConfigurationOptionsModel = new UpdateSmtpConfigurationOptions.Builder()
        .instanceId(<instanceId>)
        .id(<smtpConfigID>)
        .name(<smtpName>)
        .description(<smtpDescription>)
        .build();

Response<SMTPConfiguration> response = eventNotificationsService.updateSmtpConfiguration(updateSmtpConfigurationOptionsModel).execute();
SMTPConfiguration responseObj = response.getResult();

Update SMTP User

UpdateSmtpUserOptions updateSmtpUserOptionsModel = new UpdateSmtpUserOptions.Builder()
        .instanceId(<instanceId>)
        .id(<smtpConfigID>)
        .userId(<smtpUserID>)
        .description(<userDescription>)
        .build();

Response<SMTPUser> response = eventNotificationsService.updateSmtpUser(updateSmtpUserOptionsModel).execute();
SMTPUser responseObj = response.getResult();

Update SMTP Allowed IPs

UpdateSmtpAllowedIpsOptions updateSmtpAllowedIpsOptionsModel = new UpdateSmtpAllowedIpsOptions.Builder()
        .instanceId(<instanceId>)
        .id(<smtpConfigID>)
        .subnets(java.util.Arrays.asList("<subnet ips>"))
        .build();

Response<SMTPAllowedIPs> response = eventNotificationsService.updateSmtpAllowedIps(updateSmtpAllowedIpsOptionsModel).execute();
SMTPAllowedIPs responseObj = response.getResult();

Delete SMTP User

DeleteSmtpUserOptions deleteSmtpUserOptionsModel = new DeleteSmtpUserOptions.Builder()
        .instanceId(<instanceId>)
        .id(<smtpConfigID>)
        .userId(<smtpUserID>)
        .build();

Response<Void> response = eventNotificationsService.deleteSmtpUser(deleteSmtpUserOptionsModel).execute();
System.out.println(response);

Delete SMTP Configuration

DeleteSmtpConfigurationOptions deleteSmtpConfigurationOptionsModel = new DeleteSmtpConfigurationOptions.Builder()
        .instanceId(instanceId)
        .id(smtpConfigID)
        .build();

Response<Void> response = eventNotificationsService.deleteSmtpConfiguration(deleteSmtpConfigurationOptionsModel).execute();
System.out.println(response);

Verify SMTP

UpdateVerifySmtpOptions updateVerifySmtpOptions = new UpdateVerifySmtpOptions.Builder()
        .instanceId(instanceId)
        .id(smtpConfigID)
        .type("dkim,spf,en_authorization")
        .build();

Response<SMTPVerificationUpdateResponse> response = eventNotificationsService.updateVerifySmtp(updateVerifySmtpOptions).execute();
SMTPVerificationUpdateResponse updateVerifySmtpResponse = response.getResult();

Send Notifications

      List<String> fcmDevices = new ArrayList<String>();
      fcmDevices.add(<fcm-device-ids>);

      List<String> apnsDevices = new ArrayList<String>();
      apnsDevices.add(<apns-device-ids>);

      List<String> tagNames = new ArrayList<String>();
      tagNames.add(<tag-names>);

      List<String> devicePlatforms = new ArrayList<String>();
      devicePlatforms.add(<device-platforms>);

        String notificationDevices = "{\"user_ids\": [\"userId\"]}";
        String fcmJsonString = "{\"message\": {\"android\": {\"notification\": {\"title\": \"Alert message\",\"body\": \"Bob wants to play Poker\"},\"data\": {\"name\": \"Willie Greenholt\",\"description\": \"notification for the Poker\"}}}}";
        String apnsJsonString = "{\"alert\": \"Game Request\", \"badge\": 5 }";
        String safariJsonString = "{\"aps\":{\"alert\":{\"title\":\"FlightA998NowBoarding\",\"body\":\"BoardinghasbegunforFlightA998.\",\"action\":\"View\"},\"url-args\":[\"boarding\",\"A998\"]}}";
        String huaweiJsonString = "{\"message\":{\"android\":{\"notification\":{\"title\":\"New Message\",\"body\":\"Hello World\",\"click_action\":{\"type\":3}}}}}";
        String mailTo = "[\"abc@ibm.com\", \"def@us.ibm.com\"]";
        String smsTo = "[\"+911234567890\", \"+911224567890\"]";
        String templates = "[\"149b0e11-8a7c-4fda-a847-5d79e01b71dc\"]";
        String htmlBody = "\"Hi  ,<br/>Certificate expiring in 90 days.<br/><br/>Please login to <a href=\"https: //cloud.ibm.com/security-compliance/dashboard\">Security and Complaince dashboard</a> to find more information<br/>\"";
        
        NotificationCreate body = new NotificationCreate.Builder()
              .id(InstanceID)
              .ibmenseverity("<notification-severity>")
              .id("<notification-id>")
              .source("<source-id>")
              .ibmensourceid("<source-id>")
              .type("<notification-type>")
              .time(new java.util.Date())
              .ibmensubject("<subject>")
              .ibmenmailto(mailTo)
              .ibmensmsto(smsTo)
              .ibmentemplates(templates)
              .ibmenhtmlbody(htmlBody)
              .ibmenpushto(notificationDevices)
              .ibmenfcmbody(fcmJsonString)
              .ibmenhuaweibody(huaweiJsonString)
              .ibmenapnsbody(apnsJsonString)
              .ibmensafaribody(safariJsonString)
              .ibmendefaultshort("<short-Info>")
              .ibmendefaultlong("<long-Info>")
              .specversion("1.0")
              .build();

        SendNotificationsOptions sendNotificationsOptions = new SendNotificationsOptions.Builder()
        .instanceId(instanceId)
        .body(body)
        .build();

        Response<NotificationResponse> response = service.sendNotifications(sendNotificationsOptions).execute();
        NotificationResponse notificationResponse = response.getResult();
      
Send Notifications Variables
  • ibmenpushto - Set up the push notifications targets.
    • user_ids (Array of String) - Send notification to the specified userIds.
    • fcm_devices (Array of String) - Send notification to the list of specified Android devices.
    • apns_devices (Array of String) - Send notification to the list of specified iOS devices.
    • chrome_devices (Array of String) - Send notification to the list of specified Chrome devices.
    • firefox_devices (Array of string) - Send notification to the list of specified Firefox devices.
    • tags (Array of string) - Send notification to the devices that have subscribed to any of these tags.
    • platforms (Array of string) - Send notification to the devices of the specified platforms.
      • Pass 'G' for google (Android) devices.
      • Pass 'A' for iOS devices.
      • Pass 'WEB_FIREFOX' for Firefox browser.
      • Pass 'WEB_CHROME' for Chrome browser.
  • Event Notifications SendNotificationsOptions - Event Notifications Send Notifications method.
    • instance_id (string) - Unique identifier for IBM Cloud Event Notifications instance.
    • ibmenseverity (string) - Severity for the notifications. Some sources can have the concept of an Event severity. Hence a handy way is provided to specify a severity of the event. example: LOW, HIGH, MEDIUM
    • id* (string) - A unique identifier that identifies each event. source+id must be unique. The backend should be able to uniquely track this id in logs and other records. Send unique ID for each send notification. Same ID can be sent in case of failure of send notification. source+id will be logged in IBM Cloud Logging service. Using this combination we will be able to trace the event movement from one system to another and will aid in debugging and tracing.
    • source* (string) - Source of the notifications. This is the identifier of the event producer. A way to uniquely identify the source of the event. For IBM Cloud services this is the crn of the service instance producing the events. For API sources this can be something the event producer backend can uniquely identify itself with.
    • ibmensourceid* (string) - This is the ID of the source created in EN. This is available in the EN UI in the "Sources" section.
    • type (string) - This describes the type of event. It is of the form : This type is defined by the producer. The event type name has to be prefixed with the reverse DNS names so the event type is uniquely identified. The same event type can be produced by 2 different sources. It is highly recommended to use hyphen - as a separator instead of _.
    • data (string) - The payload for webhook notification. If data is added as part of payload then its mandatory to add datacontenttype.
    • datacontenttype - The notification content type. example: application/json
    • time (string) - Time of the notifications. UTC time stamp when the event occurred. Must be in the RFC 3339 format.
    • ibmenpushto (string) - Targets for the FCM notifications. This contains details about the destination where you want to send push notification. This attribute is mandatory for successful delivery from an Android FCM or APNS destination.
    • ibmenfcmbody (string) - Set payload string specific to Android platform [Refer this FCM official link].
    • ibmenhuaweibody (string) - Set payload string specific to Android platform [Refer this FCM official link].
    • ibmenapnsbody (string) - Set payload string specific to iOS platform [Refer this APNs official doc link].
    • ibmensafaribody (string) - Set payload string specific to safari platform [Refer this Safari official doc link].
    • ibmenapnsheaders (string) - Set headers required for the APNs message [Refer this APNs official link(Table 1 Header fields for a POST request)]
    • ibmenchromebody (string) - Message body for the Chrome notifications. Refer this official documentation for more.
    • ibmenfirefoxbody (string) - Message body for the Firefox notifications. Refer this official documentation for more.
    • ibmenchromeheaders (string) - Headers for the Chrome notifications. Refer this official documentation for more.
    • ibmenfirefoxheaders (string) - Headers for the Firefox notifications. Refer this official documentation for more.
    • ibmendefaultshort* (string) - Default short text for the message.
    • ibmendefaultlong* (string) - Default long text for the message.
    • specversion* (string) - Spec version of the Event Notifications. Default value is 1.0.
    • ibmenhtmlbody* (string) - The html body of notification for email.
    • ibmenmailto* (Array of string) - Array of email ids to which the notification to be sent.
    • ibmensmsto* (Array of string) - Array of SMS numbers to which the notification to be sent.
    • ibmentemplates* (Array of string) - Array of template IDs that needs to be applied while sending notification for custom domain email and slack destination.

Note: variable with * represents the mandatory attribute.

Set Environment

Find event_notifications.env.hide in the repo and rename it to event_notifications.env. After that add the values for,

  • EVENT_NOTIFICATIONS_URL - Add the Event Notifications service instance Url.
  • EVENT_NOTIFICATIONS_APIKEY - Add the Event Notifications service instance apikey.
  • EVENT_NOTIFICATIONS_GUID - Add the Event Notifications service instance GUID.

Optional

  • EVENT_NOTIFICATIONS_AUTH_URL - Add the IAM url if you are using IBM test cloud.

  • EVENT_NOTIFICATIONS_FCM_KEY - Add firebase server key for Android FCM destination.

  • EVENT_NOTIFICATIONS_FCM_ID - Add firebase sender Id for Android FCM destination.

  • EVENT_NOTIFICATIONS_FCM_PROJECT_ID - fcm project id

  • EVENT_NOTIFICATIONS_FCM_CLIENT_EMAIL - fcm client email

  • EVENT_NOTIFICATIONS_FCM_PRIVATE_KEY - fcm private key

  • EVENT_NOTIFICATIONS_SAFARI_CERTIFICATE - safari certificate path

  • EVENT_NOTIFICATIONS_SNOW_CLIENT_ID - service now client id

  • EVENT_NOTIFICATIONS_SNOW_CLIENT_SECRET - service now client secret

  • EVENT_NOTIFICATIONS_SNOW_USER_NAME - service now user name

  • EVENT_NOTIFICATIONS_SNOW_PASSWORD - service now password

  • EVENT_NOTIFICATIONS_SNOW_INSTANCE_NAME - service now instance name

  • EVENT_NOTIFICATIONS_COS_BUCKET_NAME - cloud object storage bucket name

  • EVENT_NOTIFICATIONS_COS_INSTANCE - cloud object storage instance id

  • EVENT_NOTIFICATIONS_COS_INSTANCE_CRN - cloud object storage instance crn

  • EVENT_NOTIFICATIONS_COS_ENDPOINT - cloud object storage end point

  • EVENT_NOTIFICATIONS_CODE_ENGINE_URL - code engine app url

  • EVENT_NOTIFICATIONS_CODE_ENGINE_PROJECT_CRN - code engine project crn

  • EVENT_NOTIFICATIONS_HUAWEI_CLIENT_SECRET - huawei client secret

  • EVENT_NOTIFICATIONS_HUAWEI_CLIENT_ID - huawei client id

  • EVENT_NOTIFICATIONS_SLACK_URL - slack webhook url

  • EVENT_NOTIFICATIONS_MS_TEAMS_URL - msteams webhook url

  • EVENT_NOTIFICATIONS_PD_ROUTING_KEY - pagerduty routing key

  • EVENT_NOTIFICATIONS_PD_API_KEY - pagerduty api key

  • EVENT_NOTIFICATIONS_TEMPLATE_BODY - base 64 encoded html content

  • EVENT_NOTIFICATIONS_SLACK_TEMPLATE_BODY - base 64 encoded json body

Questions

If you are having difficulties using this SDK or have a question about the IBM Cloud services, please ask a question at Stack Overflow.

Issues

If you encounter an issue with the project, you are welcome to submit a bug report. Before that, please search for similar issues. It's possible that someone has already reported the problem.

Open source @ IBM

Find more open source projects on the IBM Github Page

Contributing

See CONTRIBUTING.

License

The IBM Cloud Event Notifications Service Java SDK is released under the Apache 2.0 license. The license's full text can be found in LICENSE.