How to pass a parameter to dashDB query using Node-RED editor? - ibm-cloud

In Bluemix Node-RED application I use Cloudant and dashDB services. I replicated Cloudant database into dashDB which contains multiple values stored in a table like DALERT,DEVICE,ID etc.
I am trying to search records from the CLOUDANT table in my dashDB using DALERT column which value is equal to critical.
I am trying these way in Node-RED editor but unable to retrieve data from dashDB:
[
{"id":"9941f62b.66be08","type":"http in","name":"","url":"/get/specificcritical","method":"get","swaggerDoc":"","x":103.5,"y":409,"z":"c96fb1cb.36905","wires":[["b52196bf.4ade68","292d3e2e.d6d2c2"]]},
{"id":"b52196bf.4ade68","type":"function","name":"","func":"msg.Dalert=msg.payload.Dalert;\n\nreturn msg;","outputs":1,"noerr":0,"x":326,"y":353,"z":"c96fb1cb.36905","wires":[["457cf34.fba830c","d937915d.26c87"]]},
{"id":"457cf34.fba830c","type":"dashDB in","service":"dashDB-9a","query":"select * from XXXXX.CLOUDANT WHERE DALERT=?;","params":"msg.Dalert","name":"","x":510,"y":404,"z":"c96fb1cb.36905","wires":[["60d36407.9f2c9c","886c48df.7793b8"]]},
{"id":"d937915d.26c87","type":"debug","name":"","active":false,"console":"true","complete":"payload","x":599,"y":327,"z":"c96fb1cb.36905","wires":[]},
{"id":"60d36407.9f2c9c","type":"debug","name":"","active":true,"console":"false","complete":"false","x":758,"y":397,"z":"c96fb1cb.36905","wires":[]},
{"id":"886c48df.7793b8","type":"http response","name":"","x":771,"y":477,"z":"c96fb1cb.36905","wires":[]},
{"id":"292d3e2e.d6d2c2","type":"debug","name":"","active":true,"console":"true","complete":"payload","x":321,"y":483,"z":"c96fb1cb.36905","wires":[]}
]
Please let me know if there is any solution.

If I understood correct your question, you just need to modify your function node with something similar to this:
msg.dalert="critical";
return msg;
Assuming your DALERT column in the CLOUDANT table is of type VARCHAR. You may need to change it if is a different type on your database.
Running the application like:
http://yourappname.mybluemix.net/get/specificcritical
will result in output similar to this for my table:
[
{
"DALERT": "critical",
"DEVICE": "device1",
"ID": 1
},
{
"DALERT": "critical",
"DEVICE": "device3",
"ID": 3
},
{
"DALERT": "critical",
"DEVICE": "device5",
"ID": 5
}
]
Here is the new node flow I created with the changes (I added an input node with blank message just to test the flow in the editor):
[{"id":"c7468303.38b98","type":"http in","name":"","url":"/get/specificcritical","method":"get","swaggerDoc":"","x":125,"y":245,"z":"8e2ae4a.f71d518","wires":[["c685ce8c.397a3","20dfeeba.df2012"]]},{"id":"c685ce8c.397a3","type":"function","name":"","func":"msg.dalert=\"critical\";\nreturn msg;","outputs":1,"noerr":0,"x":347.5,"y":189,"z":"8e2ae4a.f71d518","wires":[["e1f8c153.1e074","1f2d6f8e.e0d29"]]},{"id":"e1f8c153.1e074","type":"dashDB in","service":"dashDB-0a","query":"select * from CLOUDANT WHERE DALERT=?;","params":"msg.dalert","name":"","x":531.5,"y":240,"z":"8e2ae4a.f71d518","wires":[["f1810e4c.0e7ef","1401dc1a.ebfe24"]]},{"id":"1f2d6f8e.e0d29","type":"debug","name":"","active":false,"console":"true","complete":"payload","x":620.5,"y":163,"z":"8e2ae4a.f71d518","wires":[]},{"id":"f1810e4c.0e7ef","type":"debug","name":"dashDB Output","active":true,"console":"false","complete":"payload","x":779.5,"y":233,"z":"8e2ae4a.f71d518","wires":[]},{"id":"1401dc1a.ebfe24","type":"http response","name":"","x":792.5,"y":313,"z":"8e2ae4a.f71d518","wires":[]},{"id":"20dfeeba.df2012","type":"debug","name":"","active":true,"console":"true","complete":"payload","x":342.5,"y":319,"z":"8e2ae4a.f71d518","wires":[]},{"id":"1f530672.e0acfa","type":"inject","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":122,"y":112,"z":"8e2ae4a.f71d518","wires":[["c685ce8c.397a3"]]}]

I got ans for question.
if we want to pass value as parameter just write msg.variable=msg.payload.variable; and return msg;
inside function node and msg.variable also declare in query parm inside dashDB IN node. eg:msg.Dalert=msg.payload.Dalert; and
critical value pass with url as http://yourappname.mybluemix.net/get/specificcritical?Dalert=critical
Its simple working node red flow
[
{"id":"9941f62b.66be08","type":"http in","name":"","url":"/get/specificcritical","method":"get","swaggerDoc":"","x":103.5,"y":409,"z":"c96fb1cb.36905","wires":[["b52196bf.4ade68","292d3e2e.d6d2c2"]]},
{"id":"b52196bf.4ade68","type":"function","name":"","func":"msg.Device=msg.payload.Device;\n\nreturn msg;","outputs":1,"noerr":0,"x":326,"y":353,"z":"c96fb1cb.36905","wires":[["457cf34.fba830c","d937915d.26c87"]]},
{"id":"457cf34.fba830c","type":"dashDB in","service":"dashDB-XX","query":"select * from XXXXX.CLOUDANT WHERE DEVICE=?","params":"msg.Device","name":"","x":510,"y":404,"z":"c96fb1cb.36905","wires":[["60d36407.9f2c9c","886c48df.7793b8"]]},
{"id":"d937915d.26c87","type":"debug","name":"","active":false,"console":"true","complete":"payload","x":599,"y":327,"z":"c96fb1cb.36905","wires":[]},
{"id":"60d36407.9f2c9c","type":"debug","name":"","active":true,"console":"false","complete":"false","x":758,"y":397,"z":"c96fb1cb.36905","wires":[]},
{"id":"886c48df.7793b8","type":"http response","name":"","x":771,"y":477,"z":"c96fb1cb.36905","wires":[]},
{"id":"292d3e2e.d6d2c2","type":"debug","name":"","active":true,"console":"true","complete":"payload","x":321,"y":483,"z":"c96fb1cb.36905","wires":[]}
]

Related

POST request to JIRA REST API to create issue of type Minutes

my $create_issue_json = '{"fields": { "project": { "key": "ABC" }, "summary": "summary for version 1", "description": "Creating an issue via REST API", "issuetype": { "name": "Minutes" }}}';
$tx1 = $jira_ua->post($url2 => json => decode_json($create_issue_json));
my $res1 = $tx1->res->body;
I try to create a jira issue of type Minutes but POST expects some fields which are not available in the issue of type Minutes. The below is the response.
{"errorMessages":["Brands: Brands is required.","Detection: Detection is required."],"errors":{"versions":"Affects Version/s is required.","components":"Component/s is required."}}
I also tried to fetch the schema using createMeta api but don't find any useful info. The below is the response from createmeta.
{"maxResults":50,"startAt":0,"total":3,"isLast":true,"values":[
{
"self":"https://some_url.com/rest/api/2/issuetype/1",
"id":"1",
"description":"A problem which impairs or prevents the functions of the product.",
"iconUrl":"https://some_url.com:8443/secure/viewavatar?size=xsmall&avatarId=25683&avatarType=issuetype",
"name":"Bug",
"subtask":false},
{
"self":"https://some_url.com:8443/rest/api/2/issuetype/12",
"id":"12",
"description":"An issue type to document minutes of meetings, telecons and the like",
"iconUrl":"https://some_url.com:8443/secure/viewavatar?size=xsmall&avatarId=28180&avatarType=issuetype",
"name":"Minutes",
"subtask":false
},
{
"self":"https://some_url.com:8443/rest/api/2/issuetype/23",
"id":"23",
"description":"Used to split an existing issue of type \"Bug\"",
"iconUrl":"https://some_url.com:8443/images/icons/cmts_SubBug.gif",
"name":"Sub Bug",
"subtask":true
}
]
}
It looks like there Jira Admin has added these as manadatory fields for all the issuetypes which I came to know after speaking with him. He has now individual configuration for different issue types and am able to create minutes.

Arbitrary HTTP API Call to Enter Cell Value into a MUTL_PICKLIST Column

I am quite new new to Smartsheets and to programming.
I am using Integromat to update various stuff in Smartsheets - 99% operations are done via a nice interface for dummies.
But I have an issue with one column which is MULTI_PICKLIST and which cannot be processed with native dummy-friendly UI.
Basically, I'm adding a new row and one of the columns on the way is the MULTI_PICKLIST one. In order to enter value into this cell, I need to make an arbitrary HTTP API call.
I know row ID, I know column ID. I just need to construct the body of the HTTP request.
The possible picklist value are: John or Maya or Paul. Assume I need to enter "John" into the column.
Attached, you will find my "progress". I obviously, I'm stuck with the BODY part. Can someone give me a little push, please? I think it's gotta be like 5 lines of code.
This is what I have:
DZ
A few things...
First, the value that you're using for URL doesn't look quite right. It should be in the following format, where {sheetId} is replaced with the ID of the sheet you're updating:
sheets/{sheetId}/rows
Second, I don't think you need the key/value that you've specified for Query String -- I'd suggest that you delete this info.
Next, I'm not sure what the other possible values are for Type (based on your screenshot, it looks like a picklist) -- but if JSON is an option, I'd suggest choosing that option instead of Text.
Finally, here's any example of the correct structure/contents for Body to update a MULTI_PICKLIST cell with the value John -- replace the value of the id property (5225480965908356) with your Row ID and replace the value of the columnId property (8436269809198980) with your Column ID:
[
{
"id": "5225480965908356",
"cells": [
{
"columnId": "8436269809198980",
"objectValue": {
"objectType": "MULTI_PICKLIST",
"values": ["John"]
}
}
]
}
]
If you want to select multiple values for a MULTI_PICKLIST cell, here's an example that specifies two values for the cell (John and Maya):
[
{
"id": "5225480965908356",
"cells": [
{
"columnId": "8436269809198980",
"objectValue": {
"objectType": "MULTI_PICKLIST",
"values": ["John", "Maya"]
}
}
]
}
]
** UPDATE **
My initial answer answer above assumed you wanted to update a cell value in a MULTI-PICKLIST column (b/c you've selected PUT for the Method value in your screenshot -- which is the verb used to update a row). Having re-read your question just now though, it sounds like maybe you want to add a new row...is that correct? If so, then the value for Method should be POST (not PUT), and Body will need to include additional objects within the cells array to specify values of other cells in the new row. The following example request (when used with the verb POST) adds a new row and populates 3 cells in that row, the first of which is a MULTI_PICKLIST cell:
[
{
"cells": [
{
"columnId": "8436269809198980",
"objectValue": {
"objectType": "MULTI_PICKLIST",
"values": ["John"]
}
},
{
"columnId": 6101753539127172,
"value": "test value"
},
{
"columnId": 4055216160040836,
"value": 10
}
]
}
]
More info about the Add Rows request can be found in the Smartsheet API docs: Add Rows.

how to get a particular field from web activity output in azure data factory

I am trying to create a pipeline where I want to store a particular value from a web activity in azure data factory, in a variable, so that I can pass it to other activities.
I want to get the export ID but I keep running into errors.
The response of the web activity looks like this:
{
"requestId": "----",
"result": [
{
"exportId": "---",
"format": "CSV",
"status": "Created",
"createdAt": "2020-12-15T16:03:01Z"
}
],
"success": true
}
I have tried the following methods but it fails: #string(activity('Web1').output.result.exportId
#string(activity('Web1').output.result[0].exportId
#string(activity('Web1').output.result.[0]
first(#string(activity('Web1').output.result)
enter image description here
enter image description here
I have tried this. Your second expression should work #string(activity('Web1').output.result[0].exportId)
My test
Output of Web activity
These expressions also work fine on my side, you can have a try:
#string(activity('Web1').output['result'][0]['exportId'])
#string(activity('Web1').output.result[0].exportId)
#string(first(activity('Web1').output['result']).exportId)
#string(json(activity('Web1').output.response)[0]['Id'])

How to increment a parameter in an Azure Data Factory Until Activity?

I am accessing a RESTful API that pages results in groups of 50 using the HTTP connector. The REST connector doesn't seem to support Client Certificates so I can't use the pagination in that.
I have a Pipeline Variable called SkipIndex that defaults to 0. Inside the Until loop I have a Copy Data Activity that works (HTTP source to BLOB sink), then a Set Variable Activity that I am trying to get to increment this Variable.
{
"name": "Add 50 to SkipIndex",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Copy next to temp",
"dependencyConditions": [
"Succeeded"
]
}
],
"userProperties": [],
"typeProperties": {
"variableName": "SkipIndex",
"value": {
"value": "50++",
"type": "Expression"
}
}
}
Everything I have tried results in errors such as "The expression contains self referencing variable. A variable cannot reference itself in the expression." and the one above with 50++ causes a sink error during debug.
How can I get the Until loop to increment this variable after it retrieves data?
Agree that REST Connector does supports pagination but does not for Client Certificates Authentication type.
For the idea of your Until activity scenario,i am tripped by the can't self-reference a variable in an expression limitation also. Maybe you could make a little trick on that: Add one more variable to persist the index number.
For example,i got 2 variables: count and indexValue
Until Activity:
Inside Until Activity:
V1:
V2:
BTW, no usage of 50++ in ADF.

Working on historical data (incrementing properties)

I'm trying to write a CEP rule that would take all the existing ACTIVE alarms and increase a specific fragment bike_alarm.priority by 1 every minute. This is the whole structure of alarm:
{
"count": 1,
"creationTime": "2018-07-09T15:30:20.790+02:00",
"time": "2014-03-03T12:03:27.845Z",
"history": {
"auditRecords": [],
"self": "https://cumulocity.com/audit/auditRecords"
},
"id": "1024",
"self": "https://cumulocity.com/alarm/alarms/1024",
"severity": "WARNING",
"source": {
"id": "22022",
"name": "01BIKE_STATION_NORTH",
"self": "https://cumulocity.com/inventory/managedObjects/22022"
},
"status": "ACTIVE",
"text": "Bike disconnected",
"type": "bike_error_01",
"bike_alarm" {
"priority": 10
}
}
This is what I managed to create (based mainly on this question):
create schema Alarm as Alarm;
create schema CollectedAlarms(
alarms List
);
create schema SingleAlarm(
alarm Alarm
);
#Name("Collecting alarms")
insert into CollectedAlarms
select findAllAlarmByTimeBetween(
current_timestamp().minus(100 day).toDate(),
current_timestamp().toDate()
) as alarms
from pattern[every timer:interval(30 sec)];
#Name("Splitting alarms")
insert into SingleAlarm
select
singleAlarm as alarm
from
CollectedAlarms as alarms unidirectional,
CollectedAlarms[alarms#type(Alarm)] as singleAlarm;
#Name("Rising priority")
insert into UpdateAlarm
select
sa.alarm.id as id,
{
"bike_alarm.priority", GetNumber(sa.alarm, "bike_alarm.priority". 0) + 1
} as fragments
from pattern [every sa = SingleAlarm -> (timer:interval(1 minutes))];
the problem is that not all alarms are founded and even those that are the incrementation don't work, priority is set to null.
Additionally, could you point me in direction of some better documentation? Is this something you use?
In general the esper documentation that you linked is the best place to look for the generic syntax.
In combination you probably sometimes also need the Cumulocity documentation for the specific stuff: http://cumulocity.com/guides/event-language/introduction
Coming to your problems:
You are miss-using a realtime processing engine to do cron-like batch operations. While it technically can be done this might not be the best approach and I will show you a different approach that you can take.
But first solving your approach:
The database queries like findAllAlarmByTimeBetween() will only return up to 2000 results and there is no way to get the next page like on the REST API of Cumulocity. Also if you say you want to handle only active alarms you should use a function that also filters for the status.
Getting null out of a function like getNumber() means the JsonPath wasn't found or the dataType is incorrect (using getNumber for a String). You can set a default value for that case as the third parameter. From you Json that you provided it looks correct though. The syntax errors in your code are copy paste errors I assume as otherwise you wouldn't have been able to deploy it.
In my opinion you should approach that differently:
On each incoming alarm raise the priority after one minute if it hasn't been cleared. Additionally trigger the 1 minute timer again. Like a loop until the alarm is cleared.
The pattern for this would like like that:
from pattern [
every e = AlarmCreated(alarm.status = CumulocityAlarmStatuses.ACTIVE)
-> (timer:interval(1 minutes)
and not AlarmUpdated(alarm.status != CumulocityAlarmStatuses.ACTIVE, alarm.id.value = e.alarm.id.value))
];
You need one with AlarmCreated which will only cover the initial increase and a second statement that triggers on your own schema which is then run in a loop.
In general try to avoid as many database calls as you can. So keep the loop counter in your schema so you only always need to execute the update call of the alarm.