Magento 2 GeoIP Lookup v1.x REST API Reference

GeoIP Lookup REST API allows you to integrate your own development with the GeoIP Lookup module using the REST API. To access the REST API, you need to take the following steps:

Step 1. Open Access to the API

  1. In the Magento backend main menu, go to System > Extensions > Integrations > New Integration > API.
  2. Select Plumrocket > GeoIP Lookup.
  3. Save changes.
  4. Flush cache.

Step 2. Make a GET Request to the API on IP address

URL http://www.YourSite.com/rest/V1/prgeoiplookup/8.8.8.8.

8.8.8.8 is an IP address from which we want to retrieve data.
www.YourSite.com is your website’s IP address.

By default, the data will be returned in XML format. To get JSON, you need to specify the data type “application/json” in the request header.

Example 1. Return all available information of an IP address using REST API. Data type in response – XML

As an example, we use the 8.8.8.8 IP address:

GET http://www.YourSite.com/rest/V1/prgeoiplookup/8.8.8.8/

Request Headers:

GET /rest/V1/prgeoiplookup/8.8.8.8
Host: www.YourSite.com
Accept: */*
User-Agent: Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)

Response Body:

<response>
	<item>
		<latitude>37.7510</latitude>
		<longitude>-97.8220</longitude>
		<continent_code>NA</continent_code>
		<continent_name>North America</continent_name>
		<country_code>US</country_code>
		<country_name>United States</country_name>
		<is_in_european_union>false</is_in_european_union>
		<database_name>Maxmind</database_name>
	</item>
</response>

Example 2. Return all available information of an IP address using REST API. Data type in response – JSON

As an example, we use the 8.8.8.8 IP address:

GET http://www.YourSite.com/rest/V1/prgeoiplookup/8.8.8.8/

Request Headers:

GET /rest/V1/prgeoiplookup/8.8.8.8
Host: www.YourSite.com
Accept: */*
User-Agent: Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)
Content-Type: application/json

Response Body:

[{"latitude":"37.7510","longitude":"-97.8220","continent_code":"NA","continent_name":"North America","country_code":"US","country_name":"United States","is_in_european_union":false,"database_name":"Maxmind"}]

In the REST API request, you can also specify the priority of using databases. By default, the sequence is as follows: Maxmind, IpToCountry, IpApi. In the REST API link, the services are specified after the IP parameter and are separated by commas (see Example 3).

Example 3. Return all available information of an IP address using REST API and specifying the priority of using services

As an example, we use the 8.8.8.8 IP address:

GET http://www.YourSite.com/rest/V1/prgeoiplookup/8.8.8.8/ipapi,maxmind,iptocountry/

Request Headers:

GET /rest/V1/prgeoiplookup/8.8.8.8/ipapi,maxmind,iptocountry/
Host: www.YourSite.com
Accept: */*
User-Agent: Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)

Response Body:

<response>
	<item>
		<country_code>US</country_code>
		<country_name>United States</country_name>
		<latitude>37.751</latitude>
		<longitude>-97.822</longitude>
		<database_name>Ipapi.Com</database_name>
		<is_in_european_union>false</is_in_european_union>
	</item>
</response>

You can also specify more than one service after the IP parameter when making a REST API request:

Let’s only use the ipapi service in the following request example:

GET http://www.YourSite.com/rest/V1/prgeoiplookup/8.8.8.8/ipapi/

Let’s use ipapi and IpToCountry services in the following request example:

GET http://www.YourSite.com/rest/V1/prgeoiplookup/8.8.8.8/ipapi,iptocountry/
Was this article helpful?