Skip to main content

Creating a rule for country targeting

📘 Information below might be outdated - please visit our recently updated API Reference

The instruction below shows how to create a rule for country targeting for the existing URL.

1) Get your API key here: https://app.short.io/settings/integrations/api-key​

  • Click "Create API key".
  • Add a Secret key.
  • Open the statistics of the short link.
  • Copy the link ID.

3) ISO codes.​

To create region targeting, you need to specify country ISO code and country region code in ISO-3166-2 format. Example: US (country) - United States; NY (region) - New York. You can find a necessary ISO code here: http://www.geonames.org

4) Install prerequisites for requests.​

pip install requests

Now everything is ready to run the following snippet. It will create a country targeting rule for a short URL.

5) Create a file: filename.py/ .js/ .rb. Use the code snippet below.​

📘

Please, replace LINK_ID, and ORIGINAL_URL with appropriate values.

import requests

url = "https://api.short.io/link_country/LINK_ID"

import json
payload = json.dumps({"country":"US","originalURL":"ORIGINAL_URL"})
headers = {
'content-type': "application/json",
'authorization': "<<apiKey>>"
}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

6) Launch the file.​

python filename.py

7) JSON Response (country targeting is created).​

Once you run the code, you will see the response.

{
"id":24158
"LinkId":2950160
"country":"US"
"originalURL":"https://dash.readme.io"
"updatedAt":"2020-06-01T11:17:20.702Z"
"createdAt":"2020-06-01T11:17:20.702Z"
}