How to use IP2Location.io API in n8n?

IP2Location.io API in n8n

Introduction

What is n8n?

n8n is an workflow automation tool to enables you to automate tasks or workflows. By using n8n, you can integrate different services and process data seamlessly. It works similar to Zapier or Make, but provides a self-hosting option which enable advanced customization. n8n provides integration or so-called nodes in their documentation. They have two type of nodes, which are the core and community nodes.

Types of Nodes for n8n

Core Nodes

The core nodes are built by the n8n team to provide various functionalities, such as making a HTTP API call, converting data to various format before download and so on. The n8n team also created pre-built actions and triggers to provide integration with various services, such as Google Sheets, WordPress, WooCommerce, PayPal and so on.

Community Nodes

Community nodes are built by the n8n community, and can be install via a NodeJS module manager called NPM. The community nodes extend the integration with more services that the n8n team have not provided. However, sometimes you will find that the neither side supports the API service that you want to use. For example, you want to use the IP2Location.io API in n8n, but you can’t found any node that is developed for this API. You may wonder what options do you have. Well, you can find out in the next paragraph.

Overview

In this article, we will guide you on how to use the IP2Location.io API in n8n. We will cover how to get an IP from a Google Sheet file, query the IP2Location.io API for geolocation data, and download the result as a CSV file.

Prerequisite

Before we start, please make sure that you have either registered with the n8n cloud for the free trial or paid account, or installed n8n in your server. For more information on installing n8n in your server, kindly visit their documentation.

This tutorial also requires you to have an IP2Location.io API key. You can sign up for a free API key if you don’t have one.

Steps to use IP2Location.io API in the n8n workflows

We will demonstrate how to look up IP addresses from Google Sheets using the IP2Location.io API and then export the result in a CSV file.

IP2Location.io API in n8n workflow

1. Login to your n8n dashboard, and go to the Workflows.

2. Create a new workflow by click on the “Add workflow” button.

Step1- Add Google Sheets Trigger

We will need to use the Google Sheet to retrieve IP addresses recorded.

1. Click on the “+” sign in the “Add first step…” box. Type Google Sheet and click on the “Google Sheets” when it appears. In the option of the triggers, click on the “On Row Added“.

Select Google Sheets for using IP2Location.io APi in n8n

2. A pop up box that contains the configuration of the trigger will show up. You will first need to configure your Google account credential. If you haven’t configured it before, click on the “ – Create New Credential – ” to add one. n8n recommends using OAuth2 for Google account credential, kindly visit their tutorial on set up Google OAuth2.

3. After that, you will need to select the Google Sheet document that you want to import into n8n. In the “Document” field, click on the dropdown list at the right and find the document. You will also need to choose the sheet that contains the IP addresses. In the “Sheet” field, click on the dropdown list at the right, and click on the sheet that you want.

Google Sheets Trigger Action in n8n

4. Click on the “Fetch Test Event” button to test if the trigger is able to get the data or not. You will see the IP addresses showed up at the “OUTPUT” panel at right side if success. Click on the “Back to canvas” when done.

Fetch test event in n8n

Step 2 – Add HTTP Request

We will need to use the “HTTP Request” core node to perform query to the IP2Location.io API using the data extracted from the file.

1. Click on the + sign near the “Google Sheets Trigger“, and search for “HTTP Request” in the search box. Click on it when it appears.

Select HTTP request for using IP2Location.io APi in n8n

2. In the configuration box, make sure the method is set to “GET“. In the “URL” field, copy and paste the base API URL which is https://api.ip2location.io/. In the “Authentication” field, click on the “Generic Credential Type” from the dropdown list. In the “Generic Auth Type” field, click on the “Query Auth” from the dropdown list.

HTTP request

3. Click on the “ – Create New Credential – ” if you haven’t saved your API key in n8n before. Change the “Query Auth account” on the top to “IP2Location.io API key“. Then, key in “key” in the Name field and your API key obtained from the IP2Location.io account dashboard in the Value field. Click on the Save button once done.

IP2Location.io API Key Auth

4. Toggle on the “Send Query Parameters“. In the “Query Parameters” section, enter “ip” in the Name field and drag on the header at the left side to the Value field.

5. Click on the “Test step” to test the action. You will see the result appeared at the “Output” panel at right side if success. Click on the “Back to canvas” when done.

Step 3 – Add Convert to File

Next, we will add an action to export the results as a CSV file.

1. Click on the + sign near the “HTTP Request“, and click on the “Files” > “Convert to File” > “Convert to CSV“.

2. Click on the “Test step” to test the action. You will see an output file is generated at the “Output” panel at right side. You can download the file to view the final result returned.

Convert to file output in n8n

Conclusion

In conclusion, n8n is a powerful tool to help you with automating the tasks of workflows. There are more services that you can integrate with n8n and IP2Location.io API service other than Google Sheets.


THE POWER OF IP GEOLOCATION API

Find a solution that help in your business.


Was this article helpful?