Currency Code from IP Address
A REST API to get currency code automatically for your website/app users
If you have a website with international customers and you wish to display your product prices in their local currency, the first step would be to automatically determine their currency code.
Here’s an easy to use API that’ll find that out for you :
https://ipapi.co/currency/
A request sent to the above endpoint will return the currency code (ISO 4217) of your location i.e. the country of the machine from which the above request originated. Alternatively, if you have an IP address and you wish to determine it’s currency code, you can query :
https://ipapi.co/8.8.8.8/currency/
The result would be USD
(i.e. Dollars). You can also get the currency name and lots of other details. Please see the documentation and usage examples : http://ipapi.co/api
Here are a few quick snippets :
Ruby
require 'net/http'puts Net::HTTP.get(URI('https://ipapi.co/currency/'))
Python
from requests import getprint get('https://ipapi.co/currency/').text
PHP
<?php
echo file_get_contents('https://ipapi.co/currency/');
?>
Node.js
var https = require('https');https.get('https://ipapi.co/currency/', function(resp){
var body = ''
resp.on('data', function(data){
body += data;
}); resp.on('end', function(){
console.log(body);
});
});
jQuery
$.get('https://ipapi.co/currency/', function(data){
console.log(data)
})
Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;public class Ipapi { public static void main(String[] args) throws IOException {
URL ipapi = new URL("https://ipapi.co/currency/"); URLConnection c = ipapi.openConnection();
c.setRequestProperty("User-Agent", "java-ipapi-client");
BufferedReader reader = new BufferedReader(
new InputStreamReader(c.getInputStream())
);
String location = reader.readLine();
reader.close(); System.out.println(location);
}}