Cancel
Showing results for 
Search instead for 
Did you mean: 

Can I access Visual Flow Creator with my mindsphere app?

Creator
Creator

I would like to know whether it is possible to access the output of a VFC flow that I have made inside my mindsphere app.

 

I have made a simple flow that fetches data at regular intervals and outputs the result in the debug console of VFC, is there a way to then either SEND this to the server of my app, or an API I can code into my app to GET the output from VFC.

 

Thanks

7 REPLIES 7

Re: Can I access Visual Flow Creator with my mindsphere app?

Siemens Genius Siemens Genius
Siemens Genius

@Toby_G you can use the HTTP node in VFC to POST to your APP. 

vfc1.png

 

Option 1: Using INJECT node and TIMESERIES node. There is an optional FUNCTION block, where you can have your logics in place. the HTTP node has a POST method which will allow you to post to your APP. 

[
    {
        "id": "1a06b68.585104a",
        "type": "inject",
        "z": "af68afd3.018c5",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "properties": "",
        "timezone": "utc",
        "betweentimesunit": "m",
        "x": 180,
        "y": 1400,
        "wires": [
            [
                "8759c4aa.b13318"
            ]
        ]
    },
    {
        "id": "8759c4aa.b13318",
        "type": "read timeseries",
        "z": "af68afd3.018c5",
        "name": "",
        "topic": "",
        "topicLabel": "",
        "assetName": "",
        "period": "60",
        "offset": "0",
        "mode": "relative",
        "from": "",
        "datetimepickerFrom": "",
        "to": "",
        "datetimepickerTo": "",
        "timezoneoffset": 0,
        "x": 380,
        "y": 1400,
        "wires": [
            [
                "19ee6afe.e86675"
            ]
        ]
    },
    {
        "id": "19ee6afe.e86675",
        "type": "function",
        "z": "af68afd3.018c5",
        "name": "Do whatever you want here",
        "func": "msg.payload = \"do what you want to do with the data in this function block\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 640,
        "y": 1400,
        "wires": [
            [
                "8e2a96d7.b35318"
            ]
        ]
    },
    {
        "id": "8e2a96d7.b35318",
        "type": "http request",
        "z": "af68afd3.018c5",
        "name": "http POST method",
        "method": "POST",
        "ret": "txt",
        "url": "",
        "timeout": "",
        "mindspherePath": "",
        "x": 890,
        "y": 1400,
        "wires": [
            [
                "c1c03eb7.8e92f"
            ]
        ],
        "_type": "node"
    },
    {
        "id": "c1c03eb7.8e92f",
        "type": "debug",
        "z": "af68afd3.018c5",
        "name": "",
        "active": true,
        "console": "false",
        "xaxis": "_time",
        "complete": "false",
        "x": 1090,
        "y": 1400,
        "wires": []
    }
]

Option 2: Everything same as Option 1, except, the INJECT & TIMESERIES nodes are replaced with SUBSCRIBE TIMESERIES node. This node will output when there is a change in the aspect that is selected. vfc2.png

[
    {
        "id": "4000ae76.c664d",
        "type": "subscribe timeseries",
        "z": "af68afd3.018c5",
        "name": "",
        "topic": "",
        "topicLabel": "",
        "assetName": "",
        "x": 370,
        "y": 1480,
        "wires": [
            [
                "90ed948c.369298"
            ]
        ]
    },
    {
        "id": "957abf2a.87a61",
        "type": "debug",
        "z": "af68afd3.018c5",
        "name": "",
        "active": true,
        "console": "false",
        "xaxis": "_time",
        "complete": "false",
        "x": 1090,
        "y": 1480,
        "wires": []
    },
    {
        "id": "90ed948c.369298",
        "type": "function",
        "z": "af68afd3.018c5",
        "name": "Do whatever you want here",
        "func": "msg.payload = \"do what you want to do with the data in this function block\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 640,
        "y": 1480,
        "wires": [
            [
                "1e625838.cc8098"
            ]
        ]
    },
    {
        "id": "1e625838.cc8098",
        "type": "http request",
        "z": "af68afd3.018c5",
        "name": "http POST method",
        "method": "POST",
        "ret": "txt",
        "url": "",
        "timeout": "",
        "mindspherePath": "",
        "x": 890,
        "y": 1480,
        "wires": [
            [
                "957abf2a.87a61"
            ]
        ]
    }
]

 

You can also add Authorization headers (if any), in your  function block like so:

msg.headers = {};
msg.headers = {"Authorization" : "Bearer eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vc29sYXJjMD..."};
msg.url="https://yourAppEndpoint.doimainName.com";
msg.payload =  {
"sensorType": "Temp",
"value": 35
}; msg.method="POST"; return msg;

Re: Can I access Visual Flow Creator with my mindsphere app?

Creator
Creator

@SriramSivakumar 

 

Could you possibly explain a little more about how to include the Authorisation headers. I have set up the flow how you described and recieve an error as follows:

"Bad status code 403. Body: "[{\"logref\":\"29a...\",\"message\":\"MindSphere Gateway error: Could not verify the provided CSRF token because your session was not found.\",\"stackTrace\":\"\"}]""

 The error occurs at the HTTP post method node.

Re: Can I access Visual Flow Creator with my mindsphere app?

Siemens Genius Siemens Genius
Siemens Genius
Hi @Toby_G,
The Authorization headers is an optional field you can pass using the HTTP node. In my example, I had the authorization header of my Bearer token. I’m not sure you copied this and got the error.

Could you please describe what you are doing with this flow and if possible, can you share the flow so that I can help you identify where the error is?

Re: Can I access Visual Flow Creator with my mindsphere app?

Creator
Creator

So the headers are added to the HTTP node itself and not set in the function block? I wasn't able to find the bearer token authorisation value so I used the CSRF-token and SESSION cookies, I presume these are not giving the correct access.

 

VFC-flow.JPG

Here I have the Timestamp node, the read timeseries node, the function block (where I have previously tried to set the headers), the HTTP post method with the url of my app and a standard debug node.

 

The code inside the function node (header values taken from the browser "inspect" extension):

msg.headers = {}
msg.headers = {
    "session" : "MDl...",
    "csrf-token" : "2bf..."
};

return msg;

The aim of the flow is to access the output data in my app.

Re: Can I access Visual Flow Creator with my mindsphere app?

Siemens Genius Siemens Genius
Siemens Genius

Hi @Toby_G ,

I think there is confusion going on here. Let me try to clarify. In your initial post, you were asking if it is possible to get the output of the VFC's flow to SEND this to server of your APP. 

 

Question #1: Is this APP that you are referring to, is it a MindSphere CloudFloundry APP or is this some service running outside of MindSphere? If this is a service running within MindSphere itself, you can use the Write TimeSeries node to write to the Asset. If this is a service running outside of MindSphere, then you will have to use the HTTP node with POST method. The function block is where you will define any logic, convert the data to any specific formats, http headers (if any) specific to your webserfice to which you are sending the data to.  The function block is totally optional and upto how your webservice handles POST requests. 

 

In my example, I've provided a msg.header field that was showing an example of how one can use a Bearer Token, if the webservice requires one. If your webservice to which you are sending data to, does not require one, you can ignore this section. 

 

Can you provide an example of how is your app URL like? If you were to use POSTMAN to send data to your APP, how are you doing it today? If you can share it, I can may be suggest how you can do it using VFC.

Re: Can I access Visual Flow Creator with my mindsphere app?

Creator
Creator

My app is a Mindsphere CloudFoundry App.

 

I use the standard MindSphere timeseries API requests as shown in the documentation, this example API url retrieves this latest data point from my asset.:

`https://gateway.${MDSP_REGION}.mindsphere.io/api/iottimeseries/v3/timeseries/${assetId}/${aspect}`
 

 My app url is also the standard MindSphere url:

https://{tenant}-{app name}-{tenant}.eu1.mindsphere.io/

 

Even without the function block setting the headers I recieve the same error message as before.

 

Sorry for the consfusion, should have made it more clear in my original post.

Re: Can I access Visual Flow Creator with my mindsphere app?

Siemens Genius Siemens Genius
Siemens Genius

@Toby_G ,

This will be considered a backend API call and you will need the bearer authorization token from your CF app to make the API calls. You won't be able to use VFC and bearer token to make API calls. From your initial question, which was not very clear, I was under the impression that you were trying to access a service outside of Mindsphere using VFC. 

 

Alternatively, you can use the Token Manager and generate service credential for your CF APP. You can then use the service credential to generate and rotate the access_token in VFC. With this access_token, you will be able to make API calls to your CF APP.

 

Screenshot 2019-07-03 at 11.51.32 PM.png

 

 

Generating your X-SPACE-AUTH-KEY using Token Manager clientId and clientSecret

Screenshot 2019-07-03 at 11.57.36 PM.png

 

 

 

Screenshot 2019-07-03 at 11.40.57 PM.png

 

 

You can see that, with the help of the Token Manager Service credential, I've generated access_token (for simplicity purpose, I used postman to generate my access_token, but you can very well use VFC to automate the whole process to generating and rotating the token too) and using the access_token, I've made a POST method to my CF hosted APP inside MindSphere.

swagger.png

 

 

[
    {
        "id": "5ccb7606.936778",
        "type": "function",
        "z": "af68afd3.018c5",
        "name": "Token Manager Service Credential",
        "func": "msg.headers = {};\nmsg.headers = {\"Authorization\" : \"Bearer eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vc2...USE-YOUR-OWN-HERE\"};\nmsg.url=\"https://gateway.eu1.mindsphere.io/api/apiappfordemo-solarc02/v1/myapi/sensors\";\nmsg.payload =  {\n  \"temperature\": 30,\n  \"humidity\": 60\n};\nmsg.method=\"POST\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 520,
        "y": 2880,
        "wires": [
            [
                "f2707d3d.9956d"
            ]
        ],
        "_type": "node"
    },
    {
        "id": "c55dcebe.45774",
        "type": "debug",
        "z": "af68afd3.018c5",
        "name": "",
        "active": true,
        "console": "false",
        "xaxis": "_time",
        "complete": "false",
        "x": 950,
        "y": 2880,
        "wires": []
    },
    {
        "id": "f2707d3d.9956d",
        "type": "http request",
        "z": "af68afd3.018c5",
        "name": "",
        "method": "use",
        "ret": "txt",
        "url": "",
        "timeout": "",
        "mindspherePath": "",
        "x": 770,
        "y": 2880,
        "wires": [
            [
                "c55dcebe.45774"
            ]
        ]
    },
    {
        "id": "5a3524da.d6e4bc",
        "type": "inject",
        "z": "af68afd3.018c5",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "properties": "",
        "timezone": "utc",
        "betweentimesunit": "m",
        "x": 260,
        "y": 2880,
        "wires": [
            [
                "5ccb7606.936778"
            ]
        ]
    }
]