Getting a list of region targeting rules

πŸ“˜

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

The instruction below shows how to get a list of region targeting rules for a URL.

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

2) Copy an ID of a short link you want to get a list of region targeting.

  • Open the statistics of the short link.
  • Copy the link ID.

3) Install prerequisites for requests.

pip install requests
npm install --save axios

Now everything is ready to run the following snippet. It will get a list of region targeting rules for a URL.

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

πŸ“˜

Please, replace link_idString with an appropriate value.

import requests
url = "https://api.short.io/link_region/link_idString"
headers = {
    'accept': "application/json",
    'authorization': "<<apiKey>>"
    }
response = requests.request("GET", url, headers=headers)
print(response.text)
const axios = require('axios');
axios.get('https://api.short.io/link_region/LINK_ID', {
   headers: {
    accept:'*/*',
    authorization: '<<apiKey>>'
}
})
.then(function (response) {
  console.log(response.data);
})
.catch(function (response) {
  console.log(response);
});
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://api.short.io/link_region/LINK_ID")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["accept"] = 'application/json'
request["authorization"] = '<<apiKey>>'
response = http.request(request)
puts response.read_body

5) Launch the file.

python filename.py
node filename.js
ruby filename.rb

6) JSON Response (list of region targeting rules).

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

[
  {
    id: 306,
    country: 'AO',
    region: '18',
    originalURL: 'https://www.blog.short.io',
    createdAt: '2020-06-01T08:46:35.000Z',
    updatedAt: '2020-06-01T08:46:35.000Z',
    link_idString:" lnk_49n_UcbM5",
    name: 'Lunda Sul'
  }
 ]