A country calling code (or dial in code or international subscriber dialing or ISD code) is a variable length numerical prefix that’s required when dialing a telephone number in another country.
Each country is assigned a unique code e.g. +1 for USA, +7 for Russia,+33 for France, +44 for UK,+49 for Germany, +61 for Australia,+852 for Hong Kong,+86 for China, +91 for India and so on.
Say you want to reach the New York Times from outside USA, you would prefix their number (i.e. “844 698 6397”) with +1, so the international number becomes “+1 844 698 6397”.
Automatic country code from IP address
Suppose you’ve got a website or a mobile app where you want to programmatically determine the international calling code of your visitor, we’ve got an API to make it super easy for you.
If you have the IP address of your visitor (e.g. 188.8.131.52), the following request will return a string with the international calling code : https://ipapi.co/184.108.40.206/country_calling_code/
It’s that easy, there’s no complex data structure data to parse.
If you are using the API on client side, you don’t even need to pass the IP address.
Simply making an AJAX call to https://ipapi.co/country_calling_code/ will return the country calling code.
Try it out in this codepen.
Reference : API docs | ipapi by Kloudend, Inc.