Skip to content

Latest commit

 

History

History
97 lines (74 loc) · 2.29 KB

README.md

File metadata and controls

97 lines (74 loc) · 2.29 KB

nyris-api

Install

npm install @nyris/nyris-api

Example usage

import NyrisAPI, { urlOrBlobToCanvas } from "@nyris/nyris-api";

const settings = {
    xOptions: 'default', // optional, see "General request options" https://docs.nyris.io/#general-request-options for available options
    apiKey: '<YOUR_API_KEY>',
    jpegQuality: 0.9, // 
    maxWidth: 500, // Maximal image size sent to server
    maxHeight: 500,
    responseFormat: 'application/offers.complete+json' // optional, see "Response type" https://docs.nyris.io/#response-type

};
const api = new NyrisAPI(settings);

const image = await urlOrBlobToCanvas("http://...");
const results = await api.findByImage(image, {});
console.log(results);

api methods

Search for an image

findByImage(canvas: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement, options: ImageSearchOptions) : Promise<SearchResult>

The image has to be an image-like HTML object. Example options:

const options = {
    geoLocation: { lat: 52.5, lon: 13.4, dist: 50 },
    cropRect: {x1: 0.3, x2: 0.7, y1: 0.3, y2: 0.7}
}

Search for an SKU (itemID)

findBySku(sku: string, mid: string): Promise<SearchResult>

Search for significant sections in the image.

findRegions(canvas: HTMLCanvasElement | HTMLVideoElement | HTMLImageElement): Promise<Region[]>

Send feedback event.

sendFeedback(sessionId: string, requestId: string, payload: FeedbackEventPayload)

See Click and conversion analytics.

Example feedback events:

// Signal a successful or failed search
const success = {
    request_id: "<REQUEST_ID>",
    timestamp: new Date(),
    session_id: "<SESSION_ID>",
    event: 'feedback',
    data: { success: true }
};

// Signal a selected region
const region = {
    request_id: "<REQUEST_ID>",
    timestamp: new Date(),
    session_id: "<SESSION_ID>",
    event: 'region',
    data: { rect: { x: 0.1, y: 0.1, w: 0.2, h: 0.2 } }
};

// Signal a clicked result
const click = {
    request_id: "<REQUEST_ID>",
    timestamp: new Date(),
    session_id: "<SESSION_ID>",
    event: 'click',
    data: { positions: [4]} // position of the result in the results list
};