Create

Some quick example text to build on the card title and make up the bulk of the card's content.

curl \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer YOUR_BEARER_AUTH_TOKEN" \
 -d "{\"redirect\":\"http://example.com/link=to&shorten=1\", \"sandbox\":\"true\"}" \
 -X POST "https://account.sl8.in/v1/links"
// Using curl
$token = 'YOUR_BEARER_AUTH_TOKEN';
$curl  = curl_init('https://account.sl8.in/v1/links');
curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_POST           => 1,
    CURLOPT_POSTFIELDS     => json_encode([
        'redirect' => 'http://example.com/link=to&shorten=1',
        'sandbox'  => true
    ]),
    CURLOPT_HTTPHEADER     => [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $token
    ]
]);

$response = json_decode(curl_exec($curl), true);
$status   = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

var_export($response, $status);
// Using axios https://github.com/axios/axios
const token    = 'YOUR_BEARER_AUTH_TOKEN';
const instance = axios.create({
    baseURL: 'https://account.sl8.in/v1/',
    headers: {
        'Authorization': 'Bearer ' + token,
        'X-Requested-With': 'XMLHttpRequest'
    }
});

instance.post('/links', {
    redirect: "http://example.com/link=to&shorten=1",
    sandbox: true
}).then(response => {
    console.log(response);
}).catch(error => {
    console.log(error);
});
string token = "YOUR_BEARER_AUTH_TOKEN";
string postFields = @"{
    ""redirect"": ""http://example.com/link=to&shorten=1"",
    ""sandbox"": ""true""
}";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://account.sl8.in/v1/links");
request.Method         = "POST";
request.ContentType    = "application/json";
request.Headers.Add("Authorization", "Bearer " + token);

using (Stream webStream = request.GetRequestStream())
using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII))
{
    requestWriter.Write(postFields);
}

try
{
    WebResponse webResponse = request.GetResponse();
    using (Stream webStream = webResponse.GetResponseStream() ?? Stream.Null)
    using (StreamReader responseReader = new StreamReader(webStream))
    {
        string response = responseReader.ReadToEnd();
        Console.Out.WriteLine(response);
    }
}
catch (Exception e)
{
    Console.Out.WriteLine(e.Message);
}
String token           = "YOUR_BEARER_AUTH_TOKEN";
URL url                = new URL("https://account.sl8.in/v1/links");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Authorization","Bearer " + token);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");

String input = "{\"redirect\":\"http://example.com/link=to&shorten=1",\"sandbox\":\"true\"}";

OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();

BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

String output;
StringBuffer response = new StringBuffer();
while ((output = br.readLine()) != null) {
    response.append(output);
}

br.close();
System.out.println(response.toString());
System.out.println(conn.getResponseCode());

conn.disconnect();
token = '705EB8E8A609E23B02DB72412FF1C704'
headers    = {
  'Authorization': 'Bearer ' + token,
  'content-type': 'application/json'
}
post_fields = {
    'redirect': 'http://example.com/link=to&shorten=1',
    'sandbox': True,
}

url = 'https://account.sl8.in/v1/links'
response = requests.post(url, json=post_fields, headers=headers)

print(response.json(), response)
token, jsonData := "705EB8E8A609E23B02DB72412FF1C704", map[string]string{
    "redirect": "http://example.com/link=to&shorten=1",
    "sandbox": "true"}
    
jsonValue, _ := json.Marshal(jsonData)
request, _ := http.NewRequest("POST", "https://account.sl8.in/v1/links", bytes.NewBuffer(jsonValue))
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Authorization", "Bearer " + token)
client := &http.Client{}
response, err := client.Do(request)

if err != nil {
        fmt.Printf("The HTTP request failed with error %s\n", err)
} else {
        data, _ := ioutil.ReadAll(response.Body)
        fmt.Println(string(data))
}
Request Headers
Name Expected Value
Content Type application/json
Authorization Bearer YOUR_API_BEARER_KEY
Request Body Examples:
{
    "Content-Type": "application/json",
    "Authorization": "Bearer 3F2CB96965298B67764A70...",
}
Full Request Body
Name Type   Optional Description
redirect string false The URL to redirect when your short link gets visited.
name string true The name of your generated short link.
link string true Sets the short link to use instead of the system generating one for you.

Example: By default, the system generates a link like http://sl8.in/Ee0gZQwa, but when this is specified eg: foo you link will look something like http://sl8.in/foo

on_exist string true Set how duplicate {{ link }} is handled:

'APPEND_NUMBER' A number is appended to the {{ link }} value eg: If specified value is foo and it already exist, it will be replaced with foo (2).

'FAIL' Link Already exist error will be thrown.
sandbox bool true Setting this to true allows you to create a test short link to ensure that your request body is formatted correctly without actually saving the link.

Request Body Examples:
{
    "name": "My Foo Link",
    "link": "foo",
    "redirect": "http://example.com/link=to&shorten=1",
    "on_exist": "APPEND_NUMBER",
    "sandbox": true
}
Response Body
Name Description
id The id of your short link.
name The name assigned to your url.
redirect The initial redirect link.
link The 8 characters long string generated for the {{ redirect }} URL.
domain User current domain.
full_link The actual short link.
Response Body Example (Based on the above request body):
{
    "id": "30",
    "name": "My Foo Link",
    "redirect": "http://example.com/link=to&shorten=1",
    "link": "foo",
    "full_link": "http://sl8.in/foo",
    "domain": "sl8"
}
Response Codes
Code Reason Description
200 OK Your request was valid and successful.
401 UNAUTHORIZED You do not have authorization to make the request.
402 PAYMENT_REQUIRED You do not have authorization to make the request.
500 SERVER UNAVAILABLE An error occurred on our server.