search

Calling the Globalization Pipeline Service from Node Red on IBM Bluemix


In this post I will show you how to quickly globalize an API in Node Red that needs to return messages in more than one language. This is really easy to do when you use the Globalization Pipeline Service on IBM Bluemix.

In our example we are going to create an API that returns a message that indicates the current status of a connected device. To make this easy we will just have some code randomly select whether the device is connected or disconnected. The API will then return a message that says “The device is connected” or “The device is not connected” depending upon the current status of the device. If you would like to see the URL in action you can click on this link for the message in English or this link for French. The URL format that we will use will be http://atkinred.mybluemix.net/device/status?lang={ISO language code}.

To get started, go ahead and bind an instance of the Globalization Pipeline service to your Node Red application and be sure to copy off the service instance id and URL for the Globalization Pipeline service from the VCAP environment variable. We will use these values later when we call the Globalization Pipeline service API.

Globalization Pipeline Service Instance ID

Globalization Pipeline Service Instance ID

The first thing that we need to do is to create a message file that contains our two messages. We will create the messages using a simple JSON syntax. Here is a screenshot that contains the two messages in a file I created called messages.json.

JSON Message File

JSON Message File

Now that we have our messages.json file created we will need to upload it to the Globalization Pipeline service by using the service’s dashboard. To upload the file all you need to do is the following:

  1. Create a resource bundle in the dashboard and name it messages.
  2. Upload the messages.json file.
  3. Select the languages that you want to translate the file into. In my example I used Spanish and French.
  4. Click Save to start the upload and translation process.
Uploading Messages

Uploading Messages

To verify that you uploaded the file correctly and that the contents were translated check the status of the messages bundle. Your screen should look something like this.

Messages Bundle Status

Messages Bundle Status

Now that we have our messages translated we need to enable access to this bundle in the Globalization Pipeline service dashboard. The Globalization Pipeline allows you to create a special read-only API key that you can safely use from client applications. With this special API key you are able to download the translated messages, but are unable to delete or change the messages. To create the read-only API key yo u need to do the following:

  1. Select the Users tab in the Globalization Pipeline service dashboard.

    Globalization Pipeline Users

    Globalization Pipeline Users

  2. Click New User
  3. For the Display name use any name you like. In my example I used node-red.
  4. Enter anything you like for the Comment.
  5. Select Reader for the Type.
  6. Select your specific bundle or all bundles. In my example I selected only the messages bundle.

    Creating New Globalization Pipeline User

    Creating New Globalization Pipeline User

  7. Click Save. Once you click Save a pop-up will be displayed that shows the User ID and Password that you will use to access your messages. Copy off these values as they will not be displayed again. If you forget to do this you will need to delete this user and create a new one.

    Reader Credentials

    Reader Credentials

Now that we have our credentials established we can call the RESTful Globalization Pipeline API from our Node Red application. To retrieve the messages from the Globalization Pipeline service we will use the GET bundle by language ID API. Here is a link to the API documentation.

To wire this all together we will create a Node Red flow that accepts an HTTP GET request to obtain the status and returns the appropriate language response via an HTTP Response. Here are the steps to create the Node Red flow:

  1. Add an HTTP In node and name it status with a URL of /device/status.
    HTTP In Status Node

    HTTP In Status Node

     

  2. Add a function node called create URL to construct the URL for accessing the Globalization Pipeline service. Be sure to use your service instance id and base path for the Globalization Service.
    Create URL Function Node

    Create URL Function Node

     

  3. Add an HTTP Request node to call the Globalization Pipeline service. Be sure to use the correct User ID and Password that you saved earlier when you added a user to the Globalization Pipeline service. You don’t need to fill in the URL as we did this programmatically in the function node.

    HTTP Request Node

    HTTP Request Node

  4. Add a function node called extract message to retrieve the correct message from calling the Globalization Pipeline service.
    Extract Message

    Extract Message

     

  5. Add an HTTP Response node to return the message.
    HTTP Response Node

    HTTP Response Node

     

  6. Wire up all the nodes as shown below and deploy your Node Red flow.

    Wired Node Red Flow

    Wired Node Red Flow

Now you have an API that will return an error message in the language of your choice. I hope this post helps you get going with creating globalized APIs in Node Red with the Globalization Pipeline service.

  1. […] some of the issues you might encounter when trying to output Unicode from OpenWhisk actions. In a previous post I showed how to call the Globalization Pipeline service from Node Red and in this post I will show […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

close
search
Latest Tweets

Hi, guest!

settings

menu