Creating a new short link with a mobile targeting rule
📘 Information below might be outdated - please visit our recently updated API Reference
The instruction below shows how to create a new short link with a rule for mobile targeting.
1) Get your secret API key here: https://app.short.io/settings/integrations/api-key​
- Click "Create API key".
- Add a Secret key.

2) Iphone and Android URLs.​
To create mobile targeting, you need to specify the URLs for iOS and Android.
3) Install prerequisites for requests.​
- Python
- Node.js
pip install requests
npm install @short.io/client-node
Now everything is ready to run the following snippet. It will create a short URL with a mobile targeting rule.
4) Create a file: filename.py/ .js/ .rb. Use the code snippet below.​
📘
Please, replace domain, original URL, iphoneURL and androidURL with appropriate values.
- Python
- Node.js
- Ruby
import requests
url = "https://api.short.io/links"
import json
payload = json.dumps({
"iphoneURL":"https://apps.apple.com/us/app/google-sheets/id842849113",
"androidURL":"https://play.google.com/store/apps/details?id=com.google.android.apps.docs.editors.sheets&hl=en",
"domain":"yourshortdomain.com",
"originalURL":"https://yourlongdomain.com/yourlonglink"})
headers = {
'accept': "application/json",
'content-type': "application/json",
'authorization': "<<apiKey>>"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
import { setApiKey, createLink } from "@short.io/client-node";
setApiKey("<<apiKey>>");
const result = await createLink({
body: {
allowDuplicates: false,
iphoneURL: "https://apps.apple.com/us/app/google-sheets/id842849113",
androidURL: "https://play.google.com/store/apps/details?id=com.google.android.apps.docs.editors.sheets&hl=en",
domain: "yourshortdomain.com",
originalURL: "https://yourlongdomain.com/yourlonglink"
}
});
console.log(result.data);
require 'uri'
require 'net/http'
require 'openssl'
require 'json'
url = URI("https://api.short.io/links")
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({"allowDuplicates":false,
"iphoneURL":"https://apps.apple.com/us/app/google-sheets/id842849113",
"androidURL":"https://play.google.com/store/apps/details?id=com.google.android.apps.docs.editors.sheets&hl=en",
"domain":"yourshortdomain.com",
"originalURL":"https://yourlongdomain.com/yourlonglink"})
response = http.request(request)
puts response.read_body
5) Launch the file.​
- Python
- Node.js
- Ruby
python filename.py
node filename.js
ruby filename.rb
6) JSON Response (link with mobile targeting is created).​
Once you run the code, you will see the response.
{
id: 277740335,
originalURL: 'https://yourlongdomain.com/yourlonglink',
DomainId: 9026,
archived: false,
path: 'rx1jPX',
redirectType: null,
androidURL: 'https://play.google.com/store/apps/details?id=com.google.android.apps.docs.editors.sheets&hl=en',
iphoneURL: 'https://apps.apple.com/us/app/google-sheets/id842849113',
createdAt: '2020-04-20T08:48:04.878Z',
OwnerId: 9346,
updatedAt: '2020-04-20T08:48:04.878Z',
secureShortURL: 'https://yourshortdomain.com/rx1jPX',
shortURL: 'https://yourshortdomain.com/rx1jPX',
duplicate: false
}