Creating a rule for country targeting

This method creates a new country targeting rule for given link

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

  • Click "Create API key".
  • Add a Secret key.

2) Copy an ID of a short link you want to add a country targeting rule.

  • 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:

4) Install prerequisites for requests.

pip install requests
npm install --save axios

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

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


Please, replace LINK_ID, and ORIGINAL_URL with appropriate values.

import requests

url = ""

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)

const axios = require('axios');

const data = {

const options = {
  headers: {
    'content-type': 'application/json',
    authorization: '<<apiKey>>'
};'', data, options)
.then(function (response) {
.catch(function (response) {
require 'uri'
require 'net/http'
require 'openssl'
require 'json'

url = URI("")

http =, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request =
request["content-type"] = 'application/json'
request["authorization"] = '<<apiKey>>'
request.body = JSON.generate({"country":"US","originalURL":"ORIGINAL_URL"})

response = http.request(request)
puts response.read_body

6) Launch the file.

node filename.js
ruby filename.rb

7) JSON Response (country targeting is created).

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