API Reference and Developer Documentation

SoftLayer Object Storage

Kraken.io API allows you to store optimized images directly in your SoftLayer Object Storage. With just a few additional parameters your optimized images will be pushed to SoftLayer in no time.

Mandatory Parameters:
userYour SoftLayer Username.
keyYour SoftLayer API Key.
containerName of a destination container on your SoftLayer account.
regionShort name of the region your container is located in. This can be one of the following:
syd01 lon02 mon01 dal05 tok02
tor01 hkg02 mex01 par01 fra02
mil01 sjc01 sng01 mel01 ams01
Optional Parameters:
pathDestination path in your container (e.g. "images/layout/header.jpg"). Defaults to root "/".
cdn_urlA boolean value (true or false) instructing Kraken.io API to return a public CDN URL of your optimized file. Defaults to false meaning the non-CDN URL will be returned.

The above parameters must be passed in a sl_store object:

{
    "sl_store": {
        "user": "your-softlayer-account",
        "key": "your-softlayer-key",
        "container": "destination-container",
        "region": "your-container-location"
    }
}

Below you can find an example of a complete JSON request that uses sl_store to push optimized image into your SoftLayer Object Storage container. We will use url option to feed the API with a URL of image to be optimized. The below request uses example (fake) credentials - you will need to replace them with your real ones.

{
    "auth": {
        "api_key": "your_api_key",
        "api_secret": "your_api_secret"
    },
    "sl_store": {
        "user": "SLOS299821-2:SL299821",
        "key": "2ccaaba70f2115de17f31744e1e09fef300c806f5b2b10ee2230129a62df0b7c",
        "container": "assets",
        "region": "fra02",
        "cdn_url": true,
        "path": "files/image.png"
    },
    "url": "https://example.com/image.png",
    "wait": true,
    "lossy": true
}
<?php

require_once("Kraken.php");

$kraken = new Kraken("your_api_key", "your_api_secret");

$params = array(
    "url" => "https://example.com/image.png",
    "wait" => true,
    "lossy" => true,
    "sl_store" => array(
        "user" => "SLOS299821-2:SL299821",
        "key" => "2ccaaba70f2115de17f31744e1e09fef300c806f5b2b10ee2230129a62df0b7c",
        "container" => "assets",
        "region" => "fra02",
        "cdn_url" => true,
        "path" => "files/image.png"
    )
);

$data = $kraken->url($params);

if ($data["success"]) {
    echo "Success. Optimized image URL: " . $data["kraked_url"];
} else {
    echo "Fail. Error message: " . $data["message"];
}
var Kraken = require("kraken");

var kraken = new Kraken({
    "api_key": "your_api_key",
    "api_secret": "your_api_secret"
});

var params = {
    "url": "https://example.com/image.png",
    "wait": true,
    "lossy": true,
    "sl_store": {
        "user": "SLOS299821-2:SL299821",
        "key": "2ccaaba70f2115de17f31744e1e09fef300c806f5b2b10ee2230129a62df0b7c",
        "container": "assets",
        "region": "fra02",
        "cdn_url": true,
        "path": "files/image.png"
    }
};

kraken.url(params, function(status) {
    if (status.success) {
        console.log("Success. Optimized image URL: %s", status.kraked_url);
    } else {
        console.log("Fail. Error message: %s", status.message);
    }
});
require 'rubygems'
require 'kraken-io'

kraken = Kraken::API.new(
    :api_key => 'your_api_key',
    :api_secret => 'your_api_secret'
)

params = {
    :wait => true,
    :lossy => true,
    :sl_store => {
        'user' => 'SLOS299821-2:SL299821',
        'key' => '2ccaaba70f2115de17f31744e1e09fef300c806f5b2b10ee2230129a62df0b7c',
        'container' => 'assets',
        'region' => 'fra02',
        'cdn_url' => true,
        'path' => 'files/image.png'
    }
}

data = kraken.url('https://example.com/image.png', params)

if data.success
    puts 'Success! Optimized image URL: ' + data.kraked_url
else
    puts 'Fail. Error message: ' + data.message
end
package main

import (
    "log"
    "github.com/kraken-io/kraken-go"
)

func main() {
    kr, err := kraken.New("your_api_key", "your_api_secret")

    if err != nil {
        log.Fatal(err)
    }

    params := map[string]interface {} {
        "wait": true,
        "lossy": true,
        "url": "https://example.com/image.png",
        "sl_store": map[string]interface {} {
            "user": "SLOS299821-2:SL299821",
            "key": "2ccaaba70f2115de17f31744e1e09fef300c806f5b2b10ee2230129a62df0b7c",
            "container": "assets",
            "region": "fra02",
            "cdn_url": true,
            "path": "files/image.png"
        }
    }

    data, err := kr.URL(params)

    if err != nil {
        log.Fatal(err)
    }

    if data["success"] != true {
        log.Println("Failed, error message ", data["message"])
    } else {
        log.Println("Success, Optimized image URL: ", data["kraked_url"])
    }
}
from krakenio import Client

api = Client('your_api_key', 'your_api_secret')

data = {
    'wait': True,
    'lossy': True,
    'sl_store': {
        'user': 'SLOS299821-2:SL299821',
        'key': '2ccaaba70f2115de17f31744e1e09fef300c806f5b2b10ee2230129a62df0b7c',
        'container': 'assets',
        'region': 'fra02',
        'cdn_url': True,
        'path': 'images/layout/header.jpg'
    }
}

result = api.url('https://example.com/image.png', data);

if result.get('success'):
    print(result.get('kraked_url'))
else:
    print(result.get('message'))

If your SoftLayer container is CDN-enabled and you've passed "cdn_url": true parameter in your JSON request the optimization and compression results will contain kraked_url which points directly to the optimized file location in your SoftLayer CDN, for example:

http://1c231.http.fra02.cdn.softlayer.net/images/layout/header.jpg

If your container is not CDN-enabled kraked_url will point to the optimized image URL in the Kraken.io API:

https://dl.kraken.io/api/ec/df/a5/c55d5668b1b5fe9e420554c4ee/header.jpg