Skip to main content

Creating a new short URL with Link Expiration

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

The instruction below shows how to create a short URL with expiration.

1) Get your secret API key here: https://app.short.io/settings/integrations/api-key​

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

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

3) Install prerequisites for requests.​

pip install requests

Now everything is ready to run the following snippet. It will create a short URL with expiration.

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

📘

Please, replace domain, original URL, expiresAt and expiredURL with appropriate values.

import requests
import time
import datetime

url = "https://api.short.io/links"

import json
payload = json.dumps({
"allowDuplicates":False,
"expiredURL":"https://analytics.google.com/analytics/web/",
"expiresAt":time.mktime(datetime.datetime.strptime("22.05.2020 15:56:53", "%d.%m.%Y %H:%M:%S").timetuple()) * 1000,
"domain":"short-domain.com",
"originalURL":"https://medium.com/"})
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: 281221653,
originalURL: 'https://www.moesif.com/',
DomainId: 902,
archived: false,
path: 'H2uuRk',
expiresAt: '2020-05-22T12:56:53.000Z',
expiredURL: 'https://analytics.google.com/analytics/web/',
redirectType: null,
createdAt: '2020-04-27T07:39:21.558Z',
OwnerId: 9346,
updatedAt: '2020-04-27T07:39:21.558Z',
secureShortURL: 'https://short-domain.com/H2uuRk',
shortURL: 'https://short-domain.com/H2uuRk',
duplicate: false
}

Here's how it looks on Short.io:​