I am polling today’s sales data from one sistem via API and I want to send a Slack notification for every new customer that made a purchase. Since I am polling every few minutes, the same “new” customer will be sent to Slack many times during the day.
I notice that the API you’re fetching the data from has the ability to filter by when the record was created, and that your cron is running every 5 mins.
In that case I would suggest setting the ‘created_at’ param in your HTTP node to
{{ $now.minus(5, 'minutes') }}
That way you’ll only be fetching records created after the last execution of the workflow.
It does not work because when i set the the ‘created_at’ param in the HTTP node to {{ $now.minus(5, ‘minutes’) }}, which sends something like 2023-03-24T11:23:22.228-03:00, the system just considers the date 2023-03-24 and returns all customers of the day.
Now it gives another idea: perhaps I can add a node to filter all dates after {{ $now.minus(5, ‘minutes’) }}
I don’t know JS at all. I tried to feed this to ChatGPT, and it suggested the following code:
< const new_items = [];
// Get static data stored with the workflow
const data = this.getWorkflowStaticData(“node”);
data.ids = data.ids || [];
for (let i = items.length - 1; i >= 0; i–) {
// Check if data is already present
if (data.ids.includes(items[i].json.ID)) {
break;
} else {
// if new data then add it to an array
new_items.push({
json: {
name: items[i].json.name,
phone_number: items[i].json.phone_number,
purchase_value: items[i].json.purchase_value
},
});
// Add the ID of the new item to the list of stored IDs
data.ids.push(items[i].json.ID);
}
}
// return an object with the items property
return {
items: new_items
};
but I am still getting ERROR: this.getWorkflowStaticData is not a function [line 4]. Isn’t getWorkflowStaticData a valid function in n8n?
.