npm install @nyris/nyris-api
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);
find(options: ImageSearchOptions, canvas: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement, filters?: Filter[], xOptions?: any) : 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}
}
findBySku(sku: string, mid: string): Promise<SearchResult>
findRegions(canvas: HTMLCanvasElement | HTMLVideoElement | HTMLImageElement): Promise<Region[]>
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
};