The Short Link API allows you to create Short Links from your applications. You can use the API in the form of a RESTful API over HTTP or using an Android or iOS app with the libraries.
RESTful HTTP API
- URL: /_ah/api/shortlink/v1/create
- HTTP Method: POST
- Input: (as a JSON message)
- target_link: the URL to which the Short Link redirects
- short_link (optional): if specified, the user requests a custom Short Link. If not present, a random Short Link will be assigned
- Example input:
{
"state": "----X----",
"target_link": "http://foo.com"
}
Output: a JSON object containing the following fields
- created_date (optional): a Unix timestamp indicating the time (in UTC) that the Short Link was created. Present if creation was a success
- short_link (optional): the Short Link code, to be prefixed with the domain (e.g. lnkr.co.za). Present if creation was a success
- status: the status of the creation operation; non-zero indicates failure
- target_link (optional): the URL to which the Short Link redirects. Present if creation was a success
- msg (optional, repeatable): Any error messages that might be appropriate. Present if creation failed
Example output:
{
"created_date": "1383588183093",
"short_link": "XScfof",
"status": "0",
"target_link": "http://lnkr.co.za"
}
Javascript API
To use the Javascript API you'll first need to include the Google API client. The value of the onload
parameter is a callback function you'll need to create.
<script src="https://apis.google.com/js/client.js?onload=init"></script>
The callback function will load the Short Link API.
var ROOT = 'https://1-dot-api.lnkr.co.za';
gapi.client.load('shortlink', 'v1', function() {
// The API is loaded, you can now use it
}, ROOT);
To create a Short Link, use the create
method.
gapi.client.shortlink.create(req).execute(function(resp) {
// req is the input
// resp is the output
});
- Input: (as a JSON message)
- target_link: the URL to which the Short Link redirects
- short_link (optional): if specified, the user requests a custom Short Link. If not present, a random Short Link will be assigned
- Example input:
{
target_link: "http://lnkr.co.za",
short_link: "customLink"
}
Output: a JSON object containing the following fields
- created_date (optional): a Unix timestamp indicating the time (in UTC) that the Short Link was created. Present if creation was a success
- short_link (optional): the Short Link code, to be prefixed with the domain (e.g. lnkr.co.za). Present if creation was a success
- status: the status of the creation operation; non-zero indicates failure
- target_link (optional): the URL to which the Short Link redirects. Present if creation was a success
- msg (optional, repeatable): Any error messages that might be appropriate. Present if creation failed
Example output:
{
"created_date": "1383588183093",
"short_link": "XScfof",
"status": "0",
"target_link": "http://lnkr.co.za"
}
Android and iOS API
You can get the data behind the stats page as JSON.
Short Link creation statistics
- URL: /data/creation
- Description: Shows the number of Short Links created per country
per day
- Output:
- An array with key "data", elements [country, count, day] with header row at position 0
- Country is the 2-letter ISO code, ZZ means unknown
- Day is the Unix timestamp (in UTC) for 00:00 on a given day
- Example output
{"data": [
["country", "count", "day"],
["ZA", 6, 1383004800000000],
["ZA", 29, 1383264000000000],
["ZA", 10, 1383523200000]
]
}
Short Link use statistics
- URL: /data/use
- Description: Shows the number of Short Links used per country per day
- Output:
- An array with key "data", elements [country, count(cached),
count(notcached)] with header row at position 0
- The cached vs. not-cached count refers to the use of
memcache when using a short link. The short link will be cached
on first use
- Country is the 2-letter ISO code, ZZ means unknown
- Day is the Unix timestamp (in UTC) for 00:00 on a given day
- Example output
{"data": [
["country", "count-notcached", "count-cached"],
["ZA", 2, 2]
]
}
Short Link data statistics
- URL: /data/linkspace
- Description: Shows stats about the usage (storage and
combinations) of the available Short Links
- Output:
- An array with key "data", elements [used, total, data_bytes] with header row at position 0
- "used" is the number of Short Links currently created
- "total" is the number of Short Links available in total
- "data_bytes" is the total storage used for Short Links
objects
- Example output
{"data": [
["used", "total", "data_bytes"],
[7, 62523502209, 1903]
]
}