NAV undefined
undefined
bash python java ruby


Introduction

PEAT API is organized around REST. We only support JSON as the all returned responses, including errors, although our API libraries convert responses to appropriate language-specific objects.

We have language bindings in Shell, Python, Java, and many more in nearly future. You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.

Authentication

# With shell, you can just pass the correct header with each request
curl "api_endpoint_here"
  -H "Api-Key: <API_KEY>"

Before you can request to the API, make sure you have Api-Key for the authentication. Please contact api@plantix.net to get your Api-Key. Your Api-Key carry many sensitive privileges, so make sure to keep it secure. Do not share your Api-Key in publicly accessible place, such as Github.

Authentication can be done by adding a header field on your request.

Rate Limit

You will have rate limit request each month. Please contact api@plantix.net to get more information about this.

Note that if you reach rate limit, the API responds with a HTTP 429 response code.

Response you'll get when you reach rate limit

{
  "message": "You have reached your maximum amount of requests this month"
}

Response

The API responds a successful requests with HTTP status code 200 or 300 range.

Example response you'll get when everything is fine

{
    "big_enough": true,
    "code": 200,
    "image_analysis": [{
            "eppo": "COCHMI",
            "name": "Brown Spot of Rice",
            "peat_id": 100064,
            "rank": 1,
            "scientific_name": "Cochliobolus miyabeanus",
            "similarity": 87
        }
    ],
    "recognized": "True",
    "recognized_bool": true
}
Response Meaning
200 OK -- Everything worked as expected
400 Bad Request -- The request was not acceptable
401 Unauthorized -- No valid Api-Key provided
429 Too Many Requests -- Rate limit request was reached
500 Internal Server Error -- Something wrong with our server (These are rare)

Image

Analyze Image

Return image analysis

Example request

curl -H "Api-Key: <YOUR_API_KEY>" -F "picture=@../data/Wheat_Leaf_Rust_100059/PEAT_20160609_122425_85d9410f-5452-42da-b471-2d80a4e9d94e.jpg" "https://api.peat-cloud.com/v1/image_analysis"
import os
import requests
from pprint import pprint as pp

IP = 'api.peat-cloud.com'
VERSION = 'v1'
ROUTE = 'image_analysis'
URL = 'https://%s/%s/%s' % (IP, VERSION, ROUTE)

# Header of our requst. Replace <YOUR_API_KEY> with your api key.
HEADER = {'Api-Key': '<YOUR_API_KEY>'}

def single_processing():

    # make a dict with the picture
    image = os.path.join('..', 'data', 'tomato_nutrient', 'iron1.png')
    files = {"picture": open(image, 'rb')}

    # post both files to our API
    result = requests.post(URL, files=files, headers=HEADER, timeout=200000)

    if result.status_code == 401:
        print('Authentication failed')
    elif result.status_code == 500:
        print('Internal server error...')
    elif result.status_code == 200:
        # load response that comes in JSON format and print the result
        json_data = result.json()
        pp(json_data)

if __name__ == '__main__':
    single_processing()
require 'net/http'
require 'uri'
require 'json'
require 'mime/types'

IP = "api.peat-cloud.com"
VERSION = "v1"
ROUTE = "image_analysis"
URL = "http://#{IP}/#{VERSION}/#{ROUTE}"

#Replace <YOUR_API_KEY> with your api key
API_KEY = "<YOUR_API_KEY>"

BOUNDARY = "%d" %Time.now.to_f.ceil

FILE = "../data/tomato_nutrient/healthy_640x480.png"

def send_request
    uri = URI(URL)
    http = Net::HTTP.new(uri.host, uri.port)


    req = Net::HTTP::Post.new(uri.path, initheader = {"Content-Type" => "multipart/form-data; boundary=#{BOUNDARY}", "Api-Key" => API_KEY})

    post_body = []

    # Add the file Data
    post_body << "--#{BOUNDARY}\r\n"
    post_body << "Content-Disposition: form-data; name=\"picture\"; filename=\"#{File.basename(FILE)}\"\r\n"
    post_body << "Content-Type: #{MIME::Types.type_for(FILE)}\r\n\r\n"
    post_body << File.read(FILE)
    post_body << "\r\n--#{BOUNDARY}--\r\n"
    req.body = post_body.join

    print req.body

    res = http.request(req)
    puts "response #{res.body}"
rescue => e
    puts "failed #{e}"
end

send_request()
package com.peat.examples;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class ImageAPIMinimal {
    private static final String API_KEY = "YOUR API KEY";
    private static final String LINE_FEED = "\r\n";

    public static void main(String[] args) throws Exception {

        String charset = StandardCharsets.UTF_8.name();

        // Your image file to upload
        File uploadFile = new File("../../../data/tomato_nutrient/iron1.jpg");
        String requestURL = "https://api.peat-cloud.com/v1/image_analysis";

        // Creates a unique boundary based on time stamp
        String boundary = String.valueOf(System.currentTimeMillis());

        // Setup http connection
        URL url = new URL(requestURL);
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
        httpConn.setUseCaches(false);
        httpConn.setDoOutput(true); // POST method
        httpConn.setRequestProperty("User-Agent", "API Java example");
        httpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
        httpConn.setRequestProperty("Api-Key", API_KEY);

        // Setup OutputStream and PrintWriter
        OutputStream outputStream = httpConn.getOutputStream();
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, charset), true);

        // Add image file to POST request
        String fieldName = "picture";
        String fileName = uploadFile.getName();
        writer.append("--" + boundary).append(LINE_FEED);
        writer.append("Content-Disposition: form-data; name=\"" + fieldName + "\"; filename=\"" + fileName + "\"").append(LINE_FEED);
        writer.append(LINE_FEED);
        writer.flush();

        FileInputStream inputStream = new FileInputStream(uploadFile);
        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, bytesRead);
        }
        outputStream.flush();
        inputStream.close();

        writer.append(LINE_FEED);
        writer.flush();

        // Send POST request and get response
        List<String> response = new ArrayList<>();
        writer.append(LINE_FEED).flush();
        writer.append("--" + boundary + "--").append(LINE_FEED);
        writer.close();

        // Check server status message
        int status = httpConn.getResponseCode();
        if (status == HttpURLConnection.HTTP_OK) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    httpConn.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                response.add(line);
            }
            reader.close();
            httpConn.disconnect();
        } else {
            throw new IOException("Server returned non-OK status: " + status);
        }

        // Read response
        for (String line : response) {
            System.out.println(line);
        }

    }
}

The code returns JSON structured like this:

{
    "big_enough": true,
    "code": 200,
    "image_analysis": [{
            "eppo": "COCHMI",
            "name": "Brown Spot of Rice",
            "peat_id": 100064,
            "rank": 1,
            "scientific_name": "Cochliobolus miyabeanus",
            "similarity": 87
        },
        {
            "eppo": "PYRIOR",
            "name": "Blast of Rice",
            "peat_id": 100058,
            "rank": 3,
            "scientific_name": "Magnaporthe oryzae",
            "similarity": 7
        }
    ],
    "objects_net": [{
            "name": "eft",
            "rank": 1,
            "similarity": 32
        },
        {
            "name": "rule",
            "rank": 2,
            "similarity": 8
        }
    ],
    "pic_id": "79937583-d368-45b9-87c1-010b55df0f5c",
    "plant_net": [{
        "name": "RICE",
        "rank": 1,
        "similarity": 94
    }],
    "recognized": "True",
    "recognized_bool": true
}

HTTP Request

POST https://api.peat-cloud.com/v1/image_analysis

Query Parameters

Parameter Description
picture A binary file of picture you want to analyze