NAV
bash javascript php

Overview

Welcome to GoPrediction Cloud API documentation. Get Postman Collection

API Authentication

We are user a simple solution to API authentication via a random token.

You can generate token in web interface.

Action Recommendation (AR)

This solution ideal for recommending products to customers based on their actions: views, likes, purchases, etc.

It works perfectly for first-time visitors, without re-train model.

Recommendations are made dynamically in real-time based on product IDs in the query.

How it works:

  1. Create new Action Recommendation instance in dashboard.
  2. Set URL to your product feed in instance.
  3. Collect actions via action method.
  4. Train data model.
  5. Get recommendations via query method.

AR JSON Feed

JSON feed should have a structure:

{"items":[
    {
        "product_id": int,
        "additional_fields": json
    },
    {
        ...
    }
]}

Example of JSON feed:

{
    "items":[ {
        "product_id":12,
        "additional_fields":"{\"product_url\":\"https:\\/\\/goprediction.com\\/api\\/v1\\/events\\/click-on-product-in-frame?product_id=12\",\"title\":\"Sp\u00f3dnica TOP SECRET,  kolekcja SLIM\",\"price\":\"119.00\",\"image_url\":\"https:\\/\\/devshop-71670.shoparena.pl\\/userdata\\/gfx\\/a4138f864d018a2a29ab2e8209ff49ff.jpg\"}"
    },
    {
        "product_id":16,
        "additional_fields":"{\"product_url\":\"https:\\/\\/goprediction.com\\/api\\/v1\\/events\\/click-on-product-in-frame?product_id=16\",\"title\":\"Sp\u00f3dnica TOP SECRET\",\"price\":\"26.90\",\"image_url\":\"https:\\/\\/devshop-71670.shoparena.pl\\/userdata\\/gfx\\/aca5f2d5ca3771784c746764f306cdc0.jpg\"}"
    },
    {
        "product_id":13,
        "additional_fields":"{\"product_url\":\"https:\\/\\/goprediction.com\\/api\\/v1\\/events\\/click-on-product-in-frame?product_id=13\",\"title\":\"Sp\u00f3dnica 4F wieczorowa\",\"price\":\"149.95\",\"image_url\":\"https:\\/\\/devshop-71670.shoparena.pl\\/userdata\\/gfx\\/5bc2deedd6db355cbb582f0db2f4c7aa.jpg\"}"
    }
  ]
}

AR Action

Storage a customer's action.

Use this method of storage customer's action on lifetime. For example from frontend via JavaScript.

Example request:

curl -X POST "https://cloud.goprediction.com/api/action-recommendation/action" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -d '{"storage_action_access_key":"eos","customer":"quas","product_id":9}'
const url = new URL("https://cloud.goprediction.com/api/action-recommendation/action");

let headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
}

let body = {
    "storage_action_access_key": "eos",
    "customer": "quas",
    "product_id": 9
}

fetch(url, {
    method: "POST",
    headers: headers,
    body: body
})
    .then(response => response.json())
    .then(json => console.log(json));

$client = new \GuzzleHttp\Client();
$response = $client->post("https://cloud.goprediction.com/api/action-recommendation/action", [
    'headers' => [
            "Content-Type" => "application/json",
            "Accept" => "application/json",
        ],
    'json' => [
            "storage_action_access_key" => "eos",
            "customer" => "quas",
            "product_id" => "9",
        ],
]);
$body = $response->getBody();
print_r(json_decode((string) $body));

Example response (200):

{
    "status": "success"
}

HTTP Request

POST api/action-recommendation/action

Body Parameters

Parameter Type Status Description
storage_action_access_key string required Storage Action Access Key.
customer string required Unique identifier of customer.
product_id integer required Unique identifier of product.

AR Query

Get recommendations

Use this method for getting recommendations.

Example request:

curl -X GET -G "https://cloud.goprediction.com/api/action-recommendation/query?query_access_key=euA8JeCr3oKRptu3&product_ids=%5B112%5D&count=1" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json"
const url = new URL("https://cloud.goprediction.com/api/action-recommendation/query");

    let params = {
            "query_access_key": "euA8JeCr3oKRptu3",
            "product_ids": "[112]",
            "count": "1",
        };
    Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));

let headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
}

fetch(url, {
    method: "GET",
    headers: headers,
})
    .then(response => response.json())
    .then(json => console.log(json));

$client = new \GuzzleHttp\Client();
$response = $client->get("https://cloud.goprediction.com/api/action-recommendation/query", [
    'headers' => [
            "Content-Type" => "application/json",
            "Accept" => "application/json",
        ],
    'query' => [
            "query_access_key" => "euA8JeCr3oKRptu3",
            "product_ids" => "[112]",
            "count" => "1",
        ],
]);
$body = $response->getBody();
print_r(json_decode((string) $body));

Example response (200):

{
    "items": [
        {
            "product_id": "33869",
            "title": "Energovital Tonik K 1000ml",
            "product_url": "https:\/\/www.store.com\/p\/Energovital-Tonik-K-1000ml.html",
            "image_url": "https:\/\/www.store.com\/userdata\/gfx\/11539.jpg",
            "price": "35.9",
            "description": "Oral fluid supporting the heart and the circulatory system",
            "score": 0.9999999999999993
        }
    ]
}

HTTP Request

GET api/action-recommendation/query

Query Parameters

Parameter Status Description
query_access_key required A Query Access Key.
product_ids required An array of product IDs.
count required Count of return items.

Get recommendation stats

Method return statistics of recommendation requests.

Example request:

curl -X GET -G "https://cloud.goprediction.com/api/action-recommendation/query/stats?date_from=2019-01-01&date_to=2019-01-03" \
    -H "Authorization: Bearer {token}" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json"
const url = new URL("https://cloud.goprediction.com/api/action-recommendation/query/stats");

    let params = {
            "date_from": "2019-01-01",
            "date_to": "2019-01-03",
        };
    Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));

let headers = {
    "Authorization": "Bearer {token}",
    "Content-Type": "application/json",
    "Accept": "application/json",
}

fetch(url, {
    method: "GET",
    headers: headers,
})
    .then(response => response.json())
    .then(json => console.log(json));

$client = new \GuzzleHttp\Client();
$response = $client->get("https://cloud.goprediction.com/api/action-recommendation/query/stats", [
    'headers' => [
            "Authorization" => "Bearer {token}",
            "Content-Type" => "application/json",
            "Accept" => "application/json",
        ],
    'query' => [
            "date_from" => "2019-01-01",
            "date_to" => "2019-01-03",
        ],
]);
$body = $response->getBody();
print_r(json_decode((string) $body));

Example response (200):

{
    "stats": [
        {
            "date": "2019-01-01",
            "requests": 346
        },
        {
            "date": "2019-01-02",
            "requests": 453
        },
        {
            "date": "2019-01-03",
            "requests": 129
        }
    ]
}

HTTP Request

GET api/action-recommendation/query/stats

Query Parameters

Parameter Status Description
date_from required Date of begin stats.
date_to required Date of end stats.

AR Train

Train model

Method init to train model data.

Example request:

curl -X POST "https://cloud.goprediction.com/api/action-recommendation/train/1" \
    -H "Authorization: Bearer {token}" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json"
const url = new URL("https://cloud.goprediction.com/api/action-recommendation/train/1");

let headers = {
    "Authorization": "Bearer {token}",
    "Content-Type": "application/json",
    "Accept": "application/json",
}

fetch(url, {
    method: "POST",
    headers: headers,
})
    .then(response => response.json())
    .then(json => console.log(json));

$client = new \GuzzleHttp\Client();
$response = $client->post("https://cloud.goprediction.com/api/action-recommendation/train/1", [
    'headers' => [
            "Authorization" => "Bearer {token}",
            "Content-Type" => "application/json",
            "Accept" => "application/json",
        ],
]);
$body = $response->getBody();
print_r(json_decode((string) $body));

Example response (200):

{
    "message": [
        "Data model was added to queue for to train."
    ]
}

HTTP Request

POST api/action-recommendation/train/{instanceId}