How to get the origin country/region of API requests

You can get the geographic information of the user who requested the API as a Smarty constant in the function.

Codes that can be used for access origin

{$smarty.const.GEO_COUNTRY_CODE} country code based on ISO 3166-2.
{$smarty.const.GEO_REGION} region code based on ISO 3166-2. In the case of the USA, it is a code of each state and district. e.g. California: CA
{$smarty.const.GEO_CONN_SPEED} connection environment code such as broadband, cable, dialup, mobile.

Add geographic information to the API which returns profile

1. Add the following code to the function.

{assign_array var=processed_json values=""}
{assign var=processed_json value=$json}
{assign var=processed_json.geo_country_code value=$smarty.const.GEO_COUNTRY_CODE}
{assign var=processed_json.geo_region value=$smarty.const.GEO_REGION}
{assign var=processed_json.geo_conn_speed value=$smarty.const.GEO_CONN_SPEED}

$json is an output result of API which can be used at API PostProcess if you set it as below.
For $processed_json, you can enter the output result after conversion by PostProcess.

2. Set above function to API PostProcess

3. Geographic information of access origin is added to API output for example like below:


## Note
Although these geographic data are categorized on an IP address basis, we do not guarantee their accuracy. Please use it only for reference.

If you have any other questions, please contact us or check out Our Slack Community.