IntegrationHub in ServiceNow Flow Designer

IntegrationHub enables integration with third-party APIs as a part of a flow. While in our previous posts we have discussed the basics of Flow Designer in ServiceNow and Custom Action in ServiceNow Flow Designer, this piece will discuss how the IntegrationHub works and not to provide a factual integration use case. We will be using the Google Cloud Translation API in our discussion.

Why IntegrationHub? As mentioned above, it enables us to integrate with external APIs as part of our process. With IntegrationHub, developers could quickly create a Spoke, or an application-specific Flow Designer actions, and have it consumed by process owners in a flow using non-technical or natural-language descriptions.

In our example below, we have created Google Cloud Translation spoke made available as a flow action. But how it was developed and how we are going to use it in our flow?

AAF25492-8808-47B7-A2D6-97783EB5A4C2.PNG
Open image in new tab to clearly view its content.
 Application. It is a collection of files and data that collectively delivers a service. This is the base element of our spoke which means that a spoke is a scope application that contains Flow Designer actions and steps.
Let us start by opening the Studio and create an application. Let us name it “Google”.
A864E782-37F2-4002-8C7A-6998102AAE90
Open image in new tab to clearly view its content.

Spoke Action. The next step is we will create a spoke action under Google application. Let us name it Google Cloud Translation. Our previous post Custom Action in ServiceNow Flow Designer provides us details in creating a Flow Designer action.

EC03275E-4B59-42BC-8FFE-46867E24EB1D.PNG
Open image in new tab to clearly view its content.

Our action has the following anatomy: Inputs or the data variables used in our action, REST Step which posts our message to and gets the response from Google Cloud Translation API, Script Step that parses the JSON response of our REST Step, and the Outputs that represent the results of the action.

We have the “Text” and “Target” input variables in this piece. The former is the text to be translated and the later is the translation target language. This is not to mention that Google Cloud Translation automatically detects the source language if not defined.

CEAA0FC9-6948-4044-90BE-7EBD03C81481.PNG
Open image in new tab to clearly view its content.

Next is our REST web service request to Google Cloud Translation API. As illustrated below, we have passed our Text and Target action inputs to “q” and “target” parameters of the API. We need as well to provide our Google Key in the “key” parameter. We have just erased our key in this illustration.

For the headers, we have just defined the Content-Type.

Notwithstanding that the recommended practice for the Connection is to use a Connection Alias, we have just used a Connection Inline is this piece.

9BBF996C-49DE-4B54-9EE5-29EED697537A.png
Open image in new tab to clearly view its content.

Then is a Script text that will parse the Response Body of our REST web service request for us to coin the values we want as outputs of our Spoke Action.

Below is the complete JSON response body that we will be parsing. Note that the Text we have passed in our request is “How are you?” and the target translation language is “Italian”. As a response, the translated text is “Come stai?” and the detected source language is “en”, and those are the values we will be parsing. Let us not forget that the Google Cloud Translation API automatically detects the source language if not defined in our request.

{
  "data": {
    "translations": [
      {
        "translatedText": "Come stai?",
        "detectedSourceLanguage": "en"
      }
    ]
  }
}

To parse those values, as mentioned earlier, we have incorporated a Script step. The step has input variable “body” that holds the Response Body of our REST step, a script that parses the response body, and output variables “translation” and “detected” that will correspondingly hold the parsed values of “translatedText” and “detectedSourceLanguage” properties of our JSON response.

98EB3FA6-455F-455C-96F5-4FB40A22C227.png
Open image in new tab to clearly view its content.

Below is the script illustrated above:

(function execute(inputs, outputs) {
	var body = JSON.parse(inputs.body);
  	outputs.translation = body.data.translations[0].translatedText;
  	outputs.detected = body.data.translations[0].detectedSourceLanguage;
})(inputs, outputs);

And now is our Action Outputs “Translation” that holds the “translation” output of our Script step, and the “Detected” that holds the “detected” output of the same script step.

8930C3C3-B979-4F2E-83D9-BE1F4EB92A32.PNG
Open image in new tab to clearly view its content.

And finally is the part that our product owner will create a Flow and use our Google Cloud Translation spoke action and pass the “Text” and “Target Language” values from a table. And using the Update Record core action, we have updated the “Translation” and “Detected Language” fields of the form.

858CED42-9ADA-46AC-A6D1-BBAAA6B9D8B8.PNG
Open image in new tab to clearly view its content.
CFACE0FF-6373-4B4F-A33C-FF301666E3F6.PNG
Open image in new tab to clearly view its content.

Hope this helps.

Leave a comment