Check if new data on Get HTTP request

I am polling an API every few minutes to get the list of customers that made a purchase today and want to pass only new data to a Google Sheet.

I don’t know JS, but I found this article Creating triggers for n8n workflows using polling ⏲ – n8n Blog and copied the code from the section " Function node (Check if new data)".

It is not working however. Any advice?

Here is the error:

Either your API has an option to get you only new purchases since the last API call - very very unlikely

OR you need to store this data from each call to compare with the next call.
Your current workflow does not handle that.
It needs to store and then check the stored value.

A simpler answer is to use Google Sheets and let that do the handling of “new” purchases by using a key and the Append or Update feature.

ie if you have a unique key like a transactionid - use that as a key.
If the key exists Google Sheet will not add it again.
If it doesnt (ie new transaction) - it will add it.
Simple !

I can create a unique transaction ID. But how do I make Google not add it again? Is that something I need to configure in Google Sheet? Or in the Google Sheet node in n8n?

@treyr in Google I added a Data validation rule to reject input when duplicate key. However Google still adds duplicate line, telling me that there is a data validation violation :sob:

I am now trying with an IF node: I need the If node to compare the new data with the data already in Google Sheet, but it doesn’t seem to be able to poll the existing data.

You dont need to do anything on the Google Sheet - just the n8n node has to be configured like this

The transaction_id is the name of the column in the Google Sheet and it should be unique and the one that comes from your API.
If the workflow sees a transaction_id in any row of the Sheet, it will update the rest of the columns
If it doesnt see any, it will add a new row.

And like any Google Sheet node, the fields/values passed to it have to match the column names - that stays unchanged

@treyr it worked!!

I checked your Google Sheet node configuration. How did you add this “key” field? It doesn’t seem to come with the standard Google Sheet node on my desktop version (0.198.)

Also, is the value imput mode important / relevant here?

I have 0.203.1.
The value input mode depends on your data - i had date fields in there which were missing formatting so I kept this option.
Not needed for deduplication

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.