API Reference and Developer Documentation
Direct Upload
Kraken.io 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
If you want to feed Kraken.io 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": "https://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" => "https://example.com/image.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: "https://example.com/image.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('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,
"url": "https://example.com/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"])
}
}
using Kraken;
using Kraken.Http;
var client = Connection.Create("your_api_key", "your_api_secret");
var response = client.OptimizeWait(
new Uri("https://example.com/image.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('https://example.com/image.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": "https://awesome-website.com/images/header.jpg"}'
Read more on: