Hello everybody! Today, I’d like to show you how to easily integrate Node-RED with SAP DMC to obtain the list of all active SFCs within a Workcenter. This integration opens up a world of possibilities for automating processes and optimizing workflows.

Why Node-RED?

Node-RED is an open-source visual programming tool that allows users to create complex logic flows for IoT (Internet of Things) applications, APIs, and other backend systems. It was developed by IBM Emerging Technology in 2013 and has since become popular among developers due to its user-friendly interface and extensibility.

With Node-RED, users can create “flows” using a drag-and-drop interface. A flow is a series of nodes that are connected together to perform a specific task or set of tasks. These flows can be customized using a wide range of pre-built nodes or by creating custom nodes using JavaScript.

Node-RED is often used for IoT applications, where it can connect to various devices and sensors to collect and process data. However, it can also be used for other backend systems such as APIs, databases, and messaging systems. Its extensibility allows it to be integrated with a wide range of systems, making it a powerful tool for developers looking to create complex backend logics.

The scenario

I know this scenario may seem straightforward, but by learning how to integrate SAP DMC REST API with Node-RED, you can unleash your creativity and extend your DMC’s capabilities to achieve anything you can imagine. With Node-RED’s visual programming interface, you can easily create custom workflows that fit your specific business needs.

So let’s get started and see what we can achieve with this powerful combination of technologies!

Pre-requisites

  • a “Service-key” created inside SAP BTP – DMC subaccount
    • Auth-token url
    • Auth url
    • Client-id
    • Client-key

SAP DMC expose a lot of “standard” services that could be used through lots of different programming languages, like:

  • Java
  • Javascript
  • ABAP
  • others

and by reaching the official documentation (https://api.sap.com/package/SAPDigitalManufacturingCloud/rest) you can expand your horizon and learn all the services (old and new) are available for the purpose of extend your SAP DMC environment.

Let’s start!

Create a new flow inside Node-RED and install a new library named “node-red-contrib-oauth2”:

this node will be used in order to obtain the bearer token and arrange the REST API Call.

Now, on our flow from scratch add a “inject” node and then attach the OAUTH node:

and now configure the oauth2 code like follow:

  • Grant Type: Client Credentials
  • Access Token Url: open SAP BTP DMC subaccount (cloudfoundry), go “Instances and Subscriptions”, go to “Instances” and open the key, here, check for the “url” and attach at the end of the url “/oauth/token”
  • Client ID: search for client id
  • Client Secret: search for Client Secret

If everything is fine, inside “msg.oauth2Response.access_token” there will be our bearer token and we are ready to make our first call!

 

Now, add a “function code” in order to prepare the header of the HTTP call and paste this code inside:

msg.headers = {
Authorization: "Bearer " + msg.oauth2Response.access_token}
return msg;

now let’s add the HTTP in node, this will be used to perform a “Get” request inside SAP DMC, in particular:

https://api.sap.com/api/sapdme_sfc/tryout

(here, you can configure your environment and try the API exposed by SAP DMC! This is useful in order to obtain the URL to be used inside Node-RED).

Add the HTTP IN node:

and configure it as:

inside URL: get the url from the “try out”, for example, for us, we are in “Demo” env, so the url is like:
https://api.test.eu20.dmc.cloud.sap/sfc/v1/sfcsInWork?plant=ZZZ&resource=YYY please replace ZZZwith your Plant and YYY with your Resource name.

Important note: the url depends on the server where your BTP is deployed, in this case, we are in EU20, and this is a Test environment.

Now, add a “Debug” node in order to print the result:

And now, let’s try by clicking on Inject node and check the result of the debug:

As you can see, we obtained the list of SFCs (in this case is only one) that are available inside our given Workcenter!

Node-RED is an extremely powerful tool that allows for easy integration with SAP DMC. By accessing the REST APIs exposed by SAP DMC through the link provided above, users can plan and build their own custom logic flows using Node-RED. This makes it possible to create tailored solutions that are specific to the needs of individual businesses, using a user-friendly visual programming interface.

 

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x