API Documentation

Developers can create shortened URLs simply and easily with the 7ls.net API. The API accepts data using the GET method and the result is returned using JSON.

Shortened URLs can be created by sending a GET request to the API which is located at http://7ls.net/api.php. The parameters for the get request are below:

Parameter Meaning Notes
request API Request create
url Long URL Must start with http:// or https://
key API Key Required

This example shows how to create a short URL for http://www.google.com using a HTTP request using PHP and cURL:


<?php

// URL to shorten
$url = "http://www.google.com";

// API Key (A valid key is needed for this API) 
$api_key = "";

// Initalize cURL
$ch = curl_init("http://7ls.net/api.php?request=create&url=".urlencode($url)."&key=".$api_key);

// Don't get header
curl_setopt($ch, CURLOPT_HEADER, false);

// Return output from curl_exec
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Follow Location: headers
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

// Execute
$ret = curl_exec($ch);

if ($ret === false) {
	die("cURL Error: ".curl_error($ch));
}

// Parse result using json_decode()
$json = json_decode($ret);

if ($json->status == "error") {
	die("API request failed. Error: " . $json->message);
}

// Short URL is in the shorturl key
$shorturl = $json->shorturl;

// Output long URL
echo "The short URL for ".$url." is ".$shorturl;
						

A JSON string is returned from the server when the URL is successfully created, which would like so:


{
	"status": "success",
	"shorturl": "http://7ls.net/abcdefg",
	"longurl": "http://www.google.com"
}

If an error occurred, then the JSON string would be something like:


{
	"status": "error",
	"message": "URL is not valid",
}

Short URLs can be turned into long URLs by sending a GET request to the API which is located at http://7ls.net/api.php. The parameters for the get request are below:

Parameter Meaning Notes
request API Request get
url Short URL Can be full URL or just path
key API Key Required

This example shows how to get a long URL from a short URL using a HTTP request using PHP and cURL:


<?php

// Short URL to get long URL for 
// Can also be "abcdefg"
$url = "http://7ls.net/abcdefg";

// API Key (A valid key is needed for this API) 
$api_key = "";

// Initalize cURL
$ch = curl_init("http://7ls.net/api.php?request=get&url=".urlencode($url)."&key=".$api_key);

// Don't get header
curl_setopt($ch, CURLOPT_HEADER, false);

// Return output from curl_exec
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Follow Location: headers
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

// Execute
$ret = curl_exec($ch);

if ($ret === false) {
	die("cURL Error: ".curl_error($ch));
}

// Parse result using json_decode()
$json = json_decode($ret);

if ($json->status == "error") {
	die("API request failed. Error: " . $json->message);
}

// Long URL is in the longurl key
$longurl = $json->longurl;

// Output long URL
echo "The long URL for ".$url." is ".$longurl;
						

A JSON string is returned from the server when the long URL is successfully retrieved, which would like so:


{
	"status": "success",
	"shorturl": "http://7ls.net/abcdefg",
	"longurl": "http://www.google.com"
}

If an error occurred, then the JSON string would be something like:


{
	"status": "error",
	"message": "URL does not exist",
}