How-tos

Create a weekly email with Bluemix Connect & Compose Service

Share this post:

Did you hear about the recent beta release of Bluemix Connect & Compose?  With Connect & Compose, you’ll be able to more easily build engaging applications through drag and drop creation of APIs, ease of connection to your business data or on premise systems, and more.  For more details about Connect & Compose, check out our previous blog Five things you need to know.

Today we’ll show you how to quickly and easily create a weekly email digest application using the Connect & Compose service.  Maybe you’re the events coordinator for your organization or maybe you want to send a quick email for individuals to quickly and easily digest all the support requests coming in this week.  In this article, we’ll create a weekly events and activities email for a new hire group at IBM. As you follow the steps below, you’ll set up a Cloudant NoSQL database, you’ll create your APIs using Connect & Compose, and you’ll Deploy the front end application to Bluemix.

Once we are done, you will have created your own event manager, utilizing the Connect & Compose service to manage all interactions with your databases containing activity and user data. Additionally, the Connect & Compose service will manage allow you to send a weekly update showcasing upcoming events on the schedule. If you’d like to see the app running in action, you can check out a demo here.

Section 1 – Setting Up The Databases

In this section, we will be setting up databases for you to store your activities and user data. To do so, we will be using two lightweight Cloudant NoSQL databases running on IBM Bluemix.

  • Go to the Bluemix Catalog.
  • In the Data & Analytics section, find Cloudant NoSQL DB, and click on the tile.
  • Give your service a name, and click CREATE to provision an instance of the Cloudant DB.
  • Once the service is provisioned, launch the Cloudant Dashboard by clicking the “Launch” button in the upper right corner.
  • Click the “Add New Database” button in the upper right corner of the dashboard.
  • Name the new database “activities” and click Create.
  • Add another database, this time naming the new database “users.”  You may have to select “Databases” from the menu on the left to return to the view of all of your databases.

Section 2 – Creating The APIs

After your databases are in place, we need a way to connect to them. Enter Connect & Compose. In this section, we will be using this service to create a set of APIs to communicate with Cloudant. Additionally, we will be using Connect & Compose to build a composition that will tie everything together. This composition will handle sending the weekly digest of upcoming events.

  • Return to the Bluemix Catalog.
  • Find the Connect & Compose service, click the tile, and provision a new instance of the service by clicking CREATE.

Create an API to connect to the activities database:

  • Click Connect
  • Name the connector (consider ‘activitiesAPI’) and click “Add Connection.”
  • Click Cloudant and then click Next.
  • You will be prompted to select a Cloudant NoSQL service instance.  Select the instance you created in Step 1, and select the “activities” database.  Click Finish
  • Scroll to the bottom of the page, and click “Finish API.”
  • Wait for the status to change from initializing to running.
  • Click on the newly created Connector.
  • Take note of the Base URL and the API Secret.  You will need this information later on.
  • Click on the SWAGGER JSON download button to save the Swagger documentation for this API:

    Rename this file to activities_swagger.json.  Save this file, as you will need it for Step 3.

Create an API to connect to the users database:

  • Follow the exact same steps as above, except select “users” database, instead of “activities” database.  To begin, click the navigation to return to the APIs list and select Connection to create a new API. Consider naming the API “usersAPI”.  Don’t forget to make note of the Base URL and API secret, as well as downloading the SWAGGER.JSON and renaming to users_swagger.json.

Create a Composition that will send the weekly digest email:

  • From the APIs list page, click Create an API from a COMPOSITION
  • Name the API and then click the ADD A COMPOSITION button.
  • Wait for the composition to load.
  • If you are redirected to the list of APIs, click the settings cog & “Edit Draft” to return to the editor.
  • Click Edit Composition
  • Once the editor loads, select the options button in the top right and click Import then Clipboard.
  • Download the following JSON flow and paste it into the import prompt.
    https://ibm.box.com/cnc-sample-compose-flow
  • Double click the “ENTER CONNECTION DETAILS HERE” node at the beginning of the flow.  In here you will need to enter the base URL & API Secret for both the activities & users APIs that you created earlier in this section.
  • Double click the “SETUP EMAIL DETAILS HERE” node at the end of the flow.  Here, you will need to enter valid email SMTP server details.  Sites like Google allow you send email via their SMTP server as long as you have valid Gmail credentials.  Do not enter a “To” field, as this will be pulled in from the users API that you created earlier.
  • Once you’ve edited those two nodes, click the green Save button in the top right corner of the editor.  Once you’ve seen the message indicating that the flow has been deployed successfully, click the left back arrow next to your API name.  This will take you back to the composition details page.
  • Scroll to the bottom of the page and click close to leave edit mode.  Now you will need to download the SWAGGER.JSON for this API, just as you did earlier with the connection APIs.  Name this JSON file email_swagger.json.

Section 3 – Deploying Your New Application

Now that everything is in place, we need to push the front-end application to Bluemix. In this section, we will take incorporate the APIs that you’ve created into a sample front-end application that is provided for you. From there, we will use Cloud Foundry tools to push and deploy your new application to IBM Bluemix.

  • Clone or download the repository from here to your local machine.  There is a download button for .zip files as well as a git URL for cloning.
    Screen Shot 2015-11-11 at 5.28.40 PM
  • Copy the three Swagger.JSON files downloaded in section 2 to <Project_Home>/public/swagger
  • Download the Cloud Foundry Command Line Interface (CLI) from here.
  • Run cf login -a https://api.ng.bluemix.net -u <Bluemix_username>.  Enter your Bluemix password and select the org and space when prompted.
  • From the <Project_Home> director, run cf push <app_name>, giving your app a unique name.
  • Once completed, your app will be available at <app_name>.mybluemix.net.

The running app should look like this:
Running App

Now that your app is hosted on Bluemix, you’re good to go! From within the running application, you can use the menu buttons to add events to the calendar. Users can also manage their subscription to your event listings. Then, whenever your list is updated, you can send the weekly digest to all subscribed users with a click of the button. Connect & Compose will handle all the heavy lifting communicating with your backend databases. All you need to do is plan the events!

Authored by:
– Cody Walker (@lostinthestory) – Software Engineer, Bluemix Cloud Integration
– Belinda Vennam (@BeeMarieV) – Software Development Manager, Bluemix Cloud Integration

More stories
May 1, 2019

Two Tutorials: Plan, Create, and Update Deployment Environments with Terraform

Multiple environments are pretty common in a project when building a solution. They support the different phases of the development cycle and the slight differences between the environments, like capacity, networking, credentials, and log verbosity. These two tutorials will show you how to manage the environments with Terraform.

Continue reading

April 29, 2019

Transforming Customer Experiences with AI Services (Part 1)

This is an experience from a recent customer engagement on transcribing customer conversations using IBM Watson AI services.

Continue reading

April 26, 2019

Analyze Logs and Monitor the Health of a Kubernetes Application with LogDNA and Sysdig

This post is an excerpt from a tutorial that shows how the IBM Log Analysis with LogDNA service can be used to configure and access logs of a Kubernetes application that is deployed on IBM Cloud.

Continue reading