This service is hosted in multiple countries. Select your preferred country to see the appropriate endpoint URLs.
Changing the hosting country does not affect the data returned by the service.
However you may wish to select a particular country based on your data residency requirements or network latency.
JSON
Copied!
Open API
Copied!
SOAP
Description
Identifies a country from a customer's IP address. Both IPv4 and IPv6 addresses are supported.
The details of the detected country are provided in the returned values. If no country could be identified, the country name and ISO code are both set to "Unknown".
If the ipAddress parameter is left blank, the IP address that the request is being made from will be used. This is particularly useful when integrating the service into a web page via JavaScript, at which point the public IP address is not known to the calling code but will be determined automatically by our service.
Credit Usage
Each request to this method consumes 1 CountryDetection credit.
Parameters
The following parameters can be supplied to this method
username
username
See the available authentication methods. If you are
using username & password authentication,
specify the username to authenticate as. If you are using
API Key authentication and you are not using
the JSON, Javascript or ADO APIs, use your API Key here with the prefix apikey-, e.g.
apikey-ABCD-1234-EFGH-5678
The IP address to detect the country for. Leave blank to use the IP address of the client.
Advanced Options
The following options can be specified as part of the option parameter. Each option is specified
as a key/value pair. The list of available names is shown below, along with a description of the allowable values
for that name.
Common Options
Name
Description
ApplicationName
ApplicationName
Gives the name of the calling application - used to break down usage by application in the usage reports on the dashboard
Results
This method returns an object containing the following fields:
Status
Status
Indicates whether the method call was successful, or if some error occurred.
If the Success field is true, the other results described below can be used to get the results of the method.
If Success is false, some error occurred in calling the method, such as the authentication failed or the
account is out of credits. The details of the error can be obtained from the ErrorMessage field, and any other results should be ignored
CountryName
CountryName
Contains the ISO standard name of the detected country
CountryISO
CountryISO
Contains the 2-character ISO code of the detected country
IDC
IDC
Contains the international telephone dialling code of the detected country
CCTLD
CCTLD
Contains the country-code top level domain name of the detected country
Live Demo
ipAddress
Credits Remaining Today:
Live Demo Results
We hope you like our service! Sign up for a free account and start using our full range of products today.
Sample Code
<!-- Import the Integr8 Ajax API --><!-- NOTE: Get your own API key to use in the following script tag from: --><!-- https://www.data-8.co.uk/ValidationAdmin/AjaxAPIKey --><scripttype="text/javascript"src="https://webservices.data-8.co.uk/Javascript/Loader.ashx?key=your-api-key&load=CountryDetection"></script><scripttype="text/javascript">function IPAddressToCountrySimple(ipAddress) {
/// <param name="ipAddress">string</param>var countrydetection = new data8.countrydetection();
countrydetection.ipaddresstocountrysimple(
ipAddress,
showIPAddressToCountrySimpleResult
);
}
function showIPAddressToCountrySimpleResult(result) {
// Check that the call succeeded, and show the error message if there was a problem.if (!result.Status.Success) {
alert('Error: ' + result.Status.ErrorMessage);
}
else {
// TODO: Process method results here.// Results can be extracted from the following fields:// result.CountryName// Contains the ISO standard name of the detected country// result.CountryISO// Contains the 2-character ISO code of the detected country// result.IDC// Contains the international telephone dialling code of the detected country// result.CCTLD// Contains the country-code top level domain name of the detected country
}
}
</script>
// NOTE: A Service Reference to the web service must be added to use this sample code.privatevoid IPAddressToCountrySimple(string ipAddress)
{
// Declare the required options.// Invoke the web service method.
CountryDetectionSoapClient proxy = new CountryDetectionSoapClient();
CountryDetectionOutput results = proxy.IPAddressToCountrySimple("your-username", "your-password", ipAddress);
// Check that the call succeeded, and show the error message if there was a problem.if ((results.Status.Success == false))
{
MessageBox.Show(("Error: " + results.Status.ErrorMessage));
}
else
{
// TODO: Process method results here.// Results can be extracted from the following fields:// result.CountryName// Contains the ISO standard name of the detected country// result.CountryISO// Contains the 2-character ISO code of the detected country// result.IDC// Contains the international telephone dialling code of the detected country// result.CCTLD// Contains the country-code top level domain name of the detected country
}
}
'NOTE: A Service Reference to the web service must be added to use this sample code.PrivateSub IPAddressToCountrySimple(ByVal ipAddress AsString)
'Declare the required options.'Invoke the web service method.Dim proxy As CountryDetectionSoapClient = New CountryDetectionSoapClient()
Dim results As CountryDetectionOutput = proxy.IPAddressToCountrySimple("your-username", "your-password", ipAddress)
'Check that the call succeeded, and show the error message if there was a problem.If (results.Status.Success = false) Then
MessageBox.Show(("Error: " + results.Status.ErrorMessage))
Else'TODO: Process method results here.'Results can be extracted from the following fields:'result.CountryName' Contains the ISO standard name of the detected country'result.CountryISO' Contains the 2-character ISO code of the detected country'result.IDC' Contains the international telephone dialling code of the detected country'result.CCTLD' Contains the country-code top level domain name of the detected countryEndIfEndSub
// NOTE: The php_soap.dll extension must be enabled in the php.ini file.function IPAddressToCountrySimple($ipAddress)
{
$options = array(
"Option" => array(
)
);
$params = array(
"username" => "your-username",
"password" => "your-password",
"ipAddress" => $ipAddress
);
$client = new SoapClient("https://webservices.data-8.co.uk/CountryDetection.asmx?WSDL");
$result = $client->IPAddressToCountrySimple($params);
if ($result->IPAddressToCountrySimpleResult->Status->Success == 0)
{
echo"Error: " . $result->IPAddressToCountrySimpleResult->Status->ErrorMessage;
}
else
{
// TODO: Process method results here.// Results can be extracted from the following fields:// $result->IPAddressToCountrySimpleResult->CountryName// Contains the ISO standard name of the detected country// $result->IPAddressToCountrySimpleResult->CountryISO// Contains the 2-character ISO code of the detected country// $result->IPAddressToCountrySimpleResult->IDC// Contains the international telephone dialling code of the detected country// $result->IPAddressToCountrySimpleResult->CCTLD// Contains the country-code top level domain name of the detected country
}
}
Post the request to https://webservices.data-8.co.uk/CountryDetection/IPAddressToCountrySimple.json?key=your-api-key
and do NOT include the username or password properties in the request JSON document.
Post the request to https://webservices.data-8.co.uk/CountryDetection/IPAddressToCountrySimple.json
and include username and password properties in the request JSON document.
Do not use for client-side requests!
Obtain a JWT token for your user and post the request to https://webservices.data-8.co.uk/CountryDetection/IPAddressToCountrySimple.json
Include the JWT token in the request headers as: Authorization: Bearer your-jwt-token
PublicSub IPAddressToCountrySimple(ipAddress AsString)
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "https://webservices.data-8.co.uk/recordset.ashx?service=CountryDetection&method=IPAddressToCountrySimpleSimple" &
"&username=your-username" &
"&password=your-password" &
"&ipAddress=" & ipAddress
If rs.MoveFirst ThenIf rs.Fields(0).Name = "Success"And rs.Fields(0).Value = falseThen
MsgBox "Error: " & rs.Fields(1)
Else'TODO: Process method results here.'All the results are available in the first row in the recordset.'Results can be extracted from the following fields:'CountryName' Contains the ISO standard name of the detected country'CountryISO' Contains the 2-character ISO code of the detected country'IDC' Contains the international telephone dialling code of the detected country'CCTLD' Contains the country-code top level domain name of the detected countryEndIfEndIfEndSub
Cookie Notice
Find out more about how this website uses cookies to enhance your browsing experience.