Verify IP from new submission and redirect flow if IP matched against previous submissions

Describe the issue/error/question -

I have a flow that my users can use once for free. When a user registers the first time, their IP address is stored in a Google sheet. I am trying to make it so that once they are registered if they come back to try and get the freebie again it ends the workflow after the IF node and sends them an email and a coupon. I have tried the IF node with no luck but I think the real problem is I don’t know how to search the IP that comes in (from the webhook) when my user signs up against the stored IP addresses of previous users in the Google Sheet. I have been so close I think but then the data that is passed is all wrong. I have learned so much about this awesome software over the last couple of months but I don’t know a lot of code and I’ve been stuck on this problem for days. Thank you for any help.

What is the error message (if any)?

No error just not getting the results I am expecting I think my process is wrong.

Please share the workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: - 0.220.0
  • Database you’re using (default: SQLite): MYSQL
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Ubuntu 22.04

Hi @wtheory, the exact process obviously depends on how your data is structured, but you probably want to use the Merge node instead of the IF node in such a scenario. It allows matching values from two different sources against each other, allowing you to compare webhook data with Google Sheet data.

Here’s an example. Let’s assume your sheet looks like this:

image

The data looks like so in n8n:

image

And let’s assume the webhook is a simple GET request (like https://your.n8n.url/webhook-test/80cc7746-fadb-404e-9598-cc78c7dfebe3?ip=1.2.3.4), meaning it looks like so in n8n:

image

Now with this information we can set up a Merge node to compare the query.ip field from our webhook with the IP field from our sheet. It can either pass on a dataset if it finds a match or pass on a dataset if there is no match.

So if you want to work with two branches (IP exists/IP does not exist) you would need to add two Merge nodes, one for each case. This is how it could look like in a workflow:

I’ve replaced the actual sheets and webhook nodes with Code nodes just providing mock data, so the workflow can run out of the box.

Now, when testing this with an IP from our sheet (like 1.2.3.4), the webhook data will be sent to the top branch:

image

When testing an IP not on the sheet (like 4.5.6.7) the bottom branch handling new IPs will run:

image

Hope this helps! Let me know if you have any questions on the example :slight_smile:

The underlying approach is also explained in more detail at https://blog.n8n.io/how-to-sync-data-between-two-systems/ (for slightly different nodes though)

@MutedJam Thank you very much, did exactly what I needed it to do. I am still wrapping my brain around the why exactly, but thank you very much. I was stumped.

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