Expanding API by a Long URL
Get a short URL by a long one
Information below might be outdated - please visit our recently updated API Reference
The instruction below shows how to get a short URL by a long one
1) Get your secret API key here: https://app.short.io/settings/integrations/api-key
- Click "Create API key".
- Add a Secret key.
2) Install prerequisites for requests.
pip install requests
npm install --save axios
Now everything is ready to run the following snippet. It will return a short URL by a long one.
3) Create a file: filename.py/ .js/ .rb. Use the code snippet below.
Please, replace domain, original URL with appropriate values.
import requests
url = "https://api.short.io/links/by-original-url"
querystring = {"domain":"short.xyz","originalURL":"https://blog.short.io/safety/"}
headers = {
'accept': "application/json",
'authorization': "<<apiKey>>"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
const axios = require('axios')
axios.get('https://api.short.io/links/by-original-url', {
params: {
domain: 'short.xyz',
originalURL: 'https://blog.short.io/safety/'
},
headers: {
accept: 'application/json', 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/links/by-original-url?domain=short.xyz&originalURL=https%3A%2F%2Fblog.short.io%2Fsafety%2F")
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
4) Launch the file.
python filename.py
node filename.js
ruby filename.rb
5) JSON Response.
Once you run the code, you will see the response.
{
id: 293945066,
path: 'k5kaSi',
title: 'How Safe is Short.io?',
icon: 'https://shortcm-icons.s3.us-west-2.amazonaws.com/b52f5518cf4bc38b47b40c21bd47a37e',
archived: false,
originalURL: 'https://blog.short.io/safety/',
iphoneURL: null,
androidURL: null,
splitURL: null,
expiresAt: null,
expiredURL: null,
redirectType: null,
cloaking: null,
source: 'website',
AutodeletedAt: null,
createdAt: '2020-05-26T13:06:34.000Z',
updatedAt: '2020-05-26T13:06:35.000Z',
DomainId: 9026,
OwnerId: 9346,
tags: [],
secureShortURL: 'https://short.xyz/k5kaSi',
shortURL: 'https://short.xyz/k5kaSi'
}
Updated over 1 year ago