Yes, I see the expected result from the expression, the date from the appropriate field. I’m pulling down around 330 records at a time and I verified in the JSON data that each of the date fields I’m using is not null. Below is the sanitized workflow.
{
"name": "Carbon Black - Decommissioned Machine Cleanup",
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
270,
160
]
},
{
"parameters": {
"triggerTimes": {
"item": [
{
"mode": "everyHour",
"minute": 15
}
]
}
},
"name": "Cron",
"type": "n8n-nodes-base.cron",
"typeVersion": 1,
"position": [
80,
300
]
},
{
"parameters": {
"url": "https://<masked>/api/queries/30/results.csv?api_key=<masked>\n",
"allowUnauthorizedCerts": true,
"responseFormat": "file",
"options": {},
"headerParametersUi": {
"parameter": []
}
},
"name": "Pull list from Redash",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
560,
300
],
"notesInFlow": true,
"notes": "Grab list of retired machines from Redash."
},
{
"parameters": {
"options": {
"headerRow": true,
"readAsString": true,
"range": "A1:A100"
}
},
"name": "Parse machine names",
"type": "n8n-nodes-base.spreadsheetFile",
"typeVersion": 1,
"position": [
740,
300
]
},
{
"parameters": {
"authentication": "headerAuth",
"requestMethod": "POST",
"url": "https://defense-prod05.conferdeploy.net/appservices/v6/orgs/<masked>/devices/_search",
"jsonParameters": true,
"options": {},
"bodyParametersJson": "={\n \"query\": \"{{$node[\"Parse machine names\"].json[\"SystemName\"]}}\"\n}"
},
"name": "Get Device IDs",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
950,
300
],
"credentials": {
"httpHeaderAuth": "Carbon Black Device Query"
}
},
{
"parameters": {
"authentication": "headerAuth",
"requestMethod": "POST",
"url": "https://defense-prod05.conferdeploy.net/appservices/v6/orgs/<masked>/device_actions",
"jsonParameters": true,
"options": {},
"bodyParametersJson": "={\n \"action_type\": \"UNINSTALL_SENSOR\",\n \"device_id\": [\"{{$json[\"deviceID\"]}}\"]\n}"
},
"name": "Deregister Endpoints",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
1480,
190
],
"credentials": {
"httpHeaderAuth": "Carbon Black Deregister Endpoint"
}
},
{
"parameters": {
"values": {
"string": [
{
"name": "deviceID",
"value": "={{$json[\"results\"][0][\"id\"]}}"
}
]
},
"options": {}
},
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
1280,
190
]
},
{
"parameters": {},
"name": "NoOp",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1450,
450
]
},
{
"parameters": {
"functionCode": "var today = new Date();\nitems[0].json.date_today = new Date(new Date().setDate(today.getDate()-30));\n\nreturn items;"
},
"name": "Get Today's Date",
"type": "n8n-nodes-base.function",
"position": [
220,
300
],
"typeVersion": 1
},
{
"parameters": {
"value": "={{$json[\"date_today\"]}}",
"dataPropertyName": "today",
"options": {}
},
"name": "Format Today's Date",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 1,
"position": [
380,
300
]
},
{
"parameters": {
"dataType": "dateTime",
"value1": "={{$node[\"Get Device IDs\"].json[\"results\"][0][\"last_contact_time\"]}}",
"rules": {
"rules": [
{
"operation": "before",
"value2": "={{$node[\"Format Today's Date\"].json[\"today\"]}}"
},
{
"value2": "={{$node[\"Format Today's Date\"].json[\"today\"]}}",
"output": 1
}
]
}
},
"name": "Validate Last Active",
"type": "n8n-nodes-base.switch",
"typeVersion": 1,
"position": [
1120,
300
],
"notes": "Because the Carbon Black API does a wildcard search in machine names, so when searching for PRVJSMITH, an inactive machine, you would also get PRVJSMITH01, an active machine. Double checking to make sure we only execute on inactive machines provides a failsafe for this edge case."
}
],
"connections": {
"Cron": {
"main": [
[
{
"node": "Get Today's Date",
"type": "main",
"index": 0
}
]
]
},
"Pull list from Redash": {
"main": [
[
{
"node": "Parse machine names",
"type": "main",
"index": 0
}
]
]
},
"Parse machine names": {
"main": [
[
{
"node": "Get Device IDs",
"type": "main",
"index": 0
}
]
]
},
"Get Device IDs": {
"main": [
[
{
"node": "Validate Last Active",
"type": "main",
"index": 0
}
]
]
},
"Set": {
"main": [
[
{
"node": "Deregister Endpoints",
"type": "main",
"index": 0
}
]
]
},
"Get Today's Date": {
"main": [
[
{
"node": "Format Today's Date",
"type": "main",
"index": 0
}
]
]
},
"Format Today's Date": {
"main": [
[
{
"node": "Pull list from Redash",
"type": "main",
"index": 0
}
]
]
},
"Validate Last Active": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"timezone": "America/Denver"
},
"id": "1"
}