---
updatedAt: 2025-11-05T21:12:03.000Z
agentTools:
  projectIndex: https://developers.short.io/llms.txt
---

# Creating a rule for region targeting

This method creates a new region targeting rule for given link

> 📘 Information below might be outdated - please visit our recently updated [API Reference](https://developers.short.io/reference/)

The instruction below shows how to create a rule for region 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.

![](https://files.readme.io/b56cfae-Screen_Shot_2021-08-11_at_2.57.06_PM.png "Screen Shot 2021-08-11 at 2.57.06 PM.png")

### **2)** Copy an ID of a short link you want to edit.

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

![](https://files.readme.io/a5095df-1.png "1.png")

![](https://files.readme.io/92fb676-Screen_Shot_2021-08-11_at_3.15.24_PM.png "Screen Shot 2021-08-11 at 3.15.24 PM.png")

### **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.

```python
pip install requests
```
```javascript Node.js
npm install --save axios
```

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

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

> 📘
>
> Please, replace link\_idString, and YOUR\_ORIGINAL\_URL with appropriate values.

```python
import requests

url = "https://api.short.io/link_region/link_idString"

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

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

print(response.text)
```
```javascript Node.js
const axios = require('axios');

const data = {
    "country":"US",
    "region":"NY",
    "originalURL":"YOUR_ORIGINAL_URL"
};

const options = {
  headers: {
    accept: 'application/json',
    'content-type': 'application/json',
    authorization: '<<apiKey>>'
  }
};

axios.post('https://api.short.io/link_region/LINK_ID', data, options)
.then(function (response) {
  console.log(response.data);
})
.catch(function (response) {
  console.log(response);
});
```
```ruby
require 'uri'
require 'net/http'
require 'openssl'
require 'json'

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::Post.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'application/json'
request["authorization"] = '<<apiKey>>'
request.body = JSON.generate({"country":"US","region":"NY","originalURL":"YOUR_ORIGINAL_URL"})

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

### **6)** Launch the file.

```python
python filename.py
```
```javascript Node.js
node filename.js
```
```ruby Ruby
ruby filename.rb
```

### **7)** JSON Response (region targeting is created).

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

```json
{
  id: 287,
  link_idString: "lnk_49n_UcbN6",
  country: 'US',
  region: 'NY',
  originalURL: 'YOUR_ORIGINAL_URL',
  updatedAt: '2020-04-16T11:09:00.915Z',
  createdAt: '2020-04-16T11:09:00.915Z',
  name: 'New York'
}
```