Skip to main content

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.​

pip install requests

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.

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)

5) Launch the file.​

python filename.py

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
}