Skip to content

Sort

This PhotoILike service provides automatic room sorting. This sorting service is intended to use the results of the PhotoScore and PhotoTag services as input, although this is not strictly necessary.

Request

POST https://api.photoilike.com/v2.0/sort

Headers

Fields

Key Value
Authorization string
Required
Session token preceded by the word Bearer.

Body of the request

The body of the request contains data with the following structure:

JSON representation

{
    "client-key": string,
    "data": [
        {
            "identifier": string,
            "label": string,
            "score": float
        },
        ...
    ],
    "preferences": [
        {
            "position": int,
            "label": string
        }
    ]
    "top": {
        "amount": int,
        "blacklist": [string, ...]
    },
}

Fields

Parameter Information
client-key string
Required
Client-key of the end user requesting image sorting.
data array
Required
Array containing the images to be sorted.
data[item].identifier string
Required
Any type of image identifier (no longer than 2000 characters). It can be a URL, a database identifier, etc.
data[item].label string
Required
Label identifying the stay (not to exceed 100 characters).
data[item].score string
Required
Score indicating the attractiveness of the image (higher is better).
preferences array
Optional
Array containing the order preference based on labels.
preferences[item].position string
Required
Label order (starts at one and increments iteratively).
preferences[item].label string
Required
Label (not to exceed 100 characters).
top object
Optional
Allows you to indicate the images that will be displayed in the top positions. In this top the best image of each label will be shown.
top.amount object
Required
Number of labels that will show their best image in the first positions.
The default value to be used, if no value is specified, is 3.
top.blacklist array
Optional
Images that contain a tag from this list will not appear in the top (labels must not exceed 100 characteres).

Response to the request

On success, the HTTP status code in the response header is 200 OK and the response body contains an array with the sorted elements.

JSON representation

[
    {
        "position": int,
        "identifier": string,
        "label": string,
        "score": float
    },
    ...
]

Fields

Parameter Information
position int
Position of the image within the set.
identifier string
Identifier of the image that has been passed to the application.
label string
Label of the image that has been passed in the request.
score string
Scoring of the image that has been passed in the application.

Example of a request

DATA='[{"identifier": "https://example.org/img12.jpg", "label": "label1", "score": 8.5}, {"identifier": "https://example.org/img11.jpg", "label": "label1", "score": 9.5}, {"identifier": "https://example.org/img31.jpg", "label": "label3", "score": 9.25}, {"identifier": "https://example.org/img22.jpg", "label": "label2", "score": 7.5}, {"identifier": "https://example.org/img21.jpg", "label": "label2", "score": 5.25}]'

PREFERENCES='[{"position": 1, "label": "label1"}, {"position": 2, "label": "label2"}, {"position": 3, "label": "labelX"}]'

curl --request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer {YOUR.SESSION.TOKEN}" \
--data '{"client-key": "{ACTIVE_CLIENT_KEY}", "data": '"$DATA"', "preferences": '"$PREFERENCES"'}' \
https://api.photoilike.com/v2.0/sort
import requests

header = {
    # Add your token session
    'Authorization': 'Bearer YOUR.SESSION.TOKEN'
}

# Add your images with their labels and scores
elements = [
    {
        'identifier': 'https://example.org/img12.jpg',
        'label': 'label1', 'score': 8.5
    }, {
        'identifier': 'https://example.org/img11.jpg',
        'label': 'label1', 'score': 9.5
    }, {
        'identifier': 'https://example.org/img31.jpg',
        'label': 'label3', 'score': 9.25
    }, {
        'identifier': 'https://example.org/img22.jpg',
        'label': 'label2', 'score': 7.5
    },
    {
        'identifier': 'https://example.org/img21.jpg',
        'label': 'label2', 'score': 5.25
    }
]

payload = {
    # Add an active client key
    'client-key': 'ACTIVE_CLIENT_KEY',
    'data': elements
}

# If you want that some labels appears on the top use the preferences
payload['preferences'] = [
    {'position': 1, 'label': 'label1'},
    {'position': 2, 'label': 'label2'},
    {'position': 3, 'label': 'labelX'}
]

endpoint = 'https://api.photoilike.com/v2.0/sort'

# Make the request
r = requests.post(endpoint, headers=header, json=payload)

# Response in json format
response = r.json()
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.json.JSONArray;
import org.json.JSONObject;

public class Sort {

    public static void main(String[] args) throws Exception {
        // add your session token
        String bearerToken = String.format("Bearer %s", "YOUR.SESSION.TOKEN");

        // add your images with their labels and scores
        JSONObject element1 = new JSONObject();
        element1.put("identifier", "https://example.org/img12.jpg");
        element1.put("label", "label1");
        element1.put("score", 8.5);
        JSONObject element2 = new JSONObject();
        element2.put("identifier", "https://example.org/img11.jpg");
        element2.put("label", "label1");
        element2.put("score", 9.5);
        JSONObject element3 = new JSONObject();
        element3.put("identifier", "https://example.org/img31.jpg");
        element3.put("label", "label3");
        element3.put("score", 9.25);
        JSONObject element4 = new JSONObject();
        element4.put("identifier", "https://example.org/img22.jpg");
        element4.put("label", "label2");
        element4.put("score", 7.5);
        JSONObject element5 = new JSONObject();
        element5.put("identifier", "https://example.org/img21.jpg");
        element5.put("label", "label2");
        element5.put("score", 5.25);

        JSONArray elements = new JSONArray();
        elements.put(element1);
        elements.put(element2);
        elements.put(element3);
        elements.put(element4);
        elements.put(element5);

        // if you want that some labels appears on the top use the preferences
        JSONObject preference1 = new JSONObject();
        preference1.put("position", 1);
        preference1.put("label", "label1");
        JSONObject preference2 = new JSONObject();
        preference2.put("position", 2);
        preference2.put("label", "label2");
        JSONObject preference3 = new JSONObject();
        preference3.put("position", 3);
        preference3.put("label", "labelX");

        JSONArray preferences = new JSONArray();
        preferences.put(preference1);
        preferences.put(preference2);
        preferences.put(preference3);

        JSONObject payload = new JSONObject();
        // add an active client key
        payload.put("client-key", "ACTIVE_CLIENT_KEY");
        payload.put("data", elements);
        payload.put("preferences", preferences);


        String endpoint = "https://api.photoilike.com/v2.0/sort";

        // build the request
        HttpURLConnection connection = (HttpURLConnection) new URL(endpoint).openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Authorization", bearerToken);
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setDoOutput(true);

        OutputStream os = connection.getOutputStream();
        byte[] input = payload.toString().getBytes(StandardCharsets.UTF_8);
        os.write(input, 0, input.length);

        // make the request
        BufferedReader br = new BufferedReader(
                new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)
        );
        StringBuilder response = new StringBuilder();

        for (String responseLine = null; (responseLine = br.readLine()) != null; response.append(responseLine.trim()))
            ;

        // Response in json format
        JSONArray json = new JSONArray(response.toString());
    }

}
<?php

  // Add your token session
  $headers = array(
    'Content-Type:application/json',
    'Authorization: Bearer YOUR.SESSION.TOKEN'
  );

  // Add your images with their labels and scores
  $elements = array(
    array(
      'identifier' => 'https://example.org/img12.jpg',
      'label' => 'label1', 'score' => 8.5
    ),
    array(
      'identifier' => 'https://example.org/img11.jpg',
      'label' => 'label1', 'score' => 9.5
    ),
    array(
      'identifier' => 'https://example.org/img31.jpg',
      'label' => 'label3', 'score' => 9.25
    ),
    array(
      'identifier' => 'https://example.org/img22.jpg',
      'label' => 'label2', 'score' => 7.5
    ),
    array(
      'identifier' => 'https://example.org/img21.jpg',
      'label' => 'label2', 'score' => 5.25
    )
  );

  // If you want that some labels appears on the top use the preferences
  $preferences = array(
    array(
      'label' => 'label1', 'position' => 1
    ),
    array(
      'label' => 'label2', 'position' => 2
    ),
    array(
      'label' => 'labelX', 'position' => 3
    )
  );

  // Add an active client key
  $payload = json_encode(array(
    'client-key' => 'ACTIVE_CLIENT_KEY',
    'data' => $elements,
    'preferences' => $preferences
  ));

  $endpoint = "https://api.photoilike.com/v2.0/sort";

  $ch = curl_init($endpoint);
  curl_setopt($ch,  CURLOPT_POSTFIELDS, $payload);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  // Make the request
  $result = curl_exec($ch);

  curl_close($ch);

  // Response in json format
  $response = json_decode($result);

 ?>