API Reference and Developer Documentation

Direct Upload

POSThttps://api.kraken.io/v1/upload

Kraken allows you to easily upload your images directly to the API. To do so you have to POST an image file along with an encoded JSON parameters string to: https://api.kraken.io/v1/upload. The names for the POST fields containing your image file and JSON options are left for you to specify. Be sure to add wait or calback_url flag to your request JSON.

{
    "auth": {
        "api_key": "your-api-key",
        "api_secret": "your-api-secret"
    },
    "wait": true
}
<?php

require_once("Kraken.php");

$kraken = new Kraken("your-api-key", "your-api-secret");

$params = array(
    "file" => "/path/to/image/file.jpg",
    "wait" => true
);

$data = $kraken->upload($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 = {
    file: "/path/to/image/file.jpg",
    wait: true
};

kraken.upload(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
}

data = kraken.upload('/path/to/image/file.jpg', 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
    }

    imgPath := "./path/to/image/file.jpg"

    data, err := kr.Upload(params, imgPath)

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

    if data["success"] != true {
        log.Println("Failed, error message ", data["message"])
    } else {
        log.Println("Success, Optimized image URL: ", data["kraked_url"])
    }
}
using Kraken;
using Kraken.Http;

var client = Connection.Create("your-api-key", "your-api-secret");
var response = client.OptimizeWait("c:\path\to\image\file.jpg");

if (response.Result.StatusCode == HttpStatusCode.OK) {
    var url = response.Result..Body.KrakedUrl;
}
from krakenio import Client

api = Client('your-api-key', 'your-api-secret')

data = {
    'wait': True
}

result = api.upload('/path/to/image/file.jpg', data);

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

Example cURL request:

curl https://api.kraken.io/v1/upload \
-X POST \
--form data='{"auth":{"api_key": "your-api-key", "api_secret": "your-api-secret"}, "wait":true}' \
--form upload=@path/to/image/file.jpg

Read more on:

Image URL

POSThttps://api.kraken.io/v1/url

If you want to feed Kraken with URLs to your images add a url property along with an auth section in your request JSON and post it to: https://api.kraken.io/v1/url. The name for the POST field containing your JSON options is left for you to specify. Be sure to add a wait or calback_url flag to your request JSON.

If HTTP Basic Authentication is enabled on your webserver simply include the username and password as part of the image URL like so: https://username:password@awesome-website.com/images/header.png

{
    "auth": {
        "api_key": "your-api-key",
        "api_secret": "your-api-secret"
    },
    "url": "http://awesome-website.com/images/header.jpg",
    "wait": true
}
<?php

require_once("Kraken.php");

$kraken = new Kraken("your-api-key", "your-api-secret");

$params = array(
    "url" => "http://awesome-website.com/images/header.png",
    "wait" => true
);

$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: "http://awesome-website.com/images/header.png",
    wait: true
};

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
}

data = kraken.url('http://awesome-website.com/images/header.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,
        "url": "http://awesome-website.com/images/header.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"])
    }
}
using Kraken;
using Kraken.Http;

var client = Connection.Create("your-api-key", "your-api-secret");

var response = client.OptimizeWait(
    new Uri("http://awesome-website.com/images/header.png")
);

if (response.Result.StatusCode == HttpStatusCode.OK) {
    var url = response.Result..Body.KrakedUrl;
}
from krakenio import Client

api = Client('your-api-key', 'your-api-secret')

data = {
    'wait': True
}

result = api.url('http://awesome-website.com/images/header.png', data);

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

Example cURL request:

curl https://api.kraken.io/v1/url \
-X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"auth":{"api_key": "your-api-key", "api_secret": "your-api-secret"}, "wait":true, "url": "http://awesome-website.com/images/header.jpg"}'

Read more on: