How to Call OpenWhisk Actions from Node Red
This post is to help you get started with calling your OpenWhisk actions from Node Red on IBM Bluemix. I will explain how you can quickly invoke your action using OpenWhisk’s RESTful API from a Node Red flow using the HTTP Request Node. To get started you need to define your action using the wsk command line utility. For instructions on how to define wsk actions follow this link.
Now that we have our action defined we need to obtain the credentials and URL to access the action as a RESTful API. To obtain this information we are going to invoke the action from the command line using the wsk utility with the -v option so that we can see all the details of what occurred when we invoked the action.
Here is a screenshot of a portion of the output after we issue the command. The key elements that we will copy are the URL and the Headers.
Now we are ready to setup the call to our RESTful action from a Node Red flow. The first thing that we will do is to create a Function Node and set the url and headers parameters that we will use when we invoke the Node Red HTTP Request Node. Here is a screen shot that shows how I defined my Function Node.
The next step is to wire the output of the Function Node to an HTTP Request Node. Here is how I configured my HTTP Request Node. Be certain to use the POST method and indicate that the return type is a parsed JSON object.
The next step is to extract the JSON result from the call to the RESTful action. You need to do this as you cannot indicate that you only want to have the result returned when calling an OpenWhisk action from the RESTful API. All you need to do is to create a Function Node to extract the result. Here is a screenshot of my Function Node.
The last step is to simply wire up your Node Red flow. Here is how I wired up my flow.
I hope this post has helped you get started with calling OpenWhisk actions from Node Red.