constructorio
v2.6.1
Published
Constructor.io API client
Downloads
21
Readme
Constructor-IO JavaScript Client
Constructor.io provides search as a service that optimizes results using artificial intelligence (including natural language processing, re-ranking to optimize for conversions, and user personalization).
Documentation
For the most up-to-date documentation for this library, please visit our API Documentation.
Installation
With npm:
npm install constructorio
Usage
Create a new instance with your API token and API key (available from the Customer Dashboard):
var ConstructorIO = require('constructorio');
var constructorio = new ConstructorIO({
apiToken: "your API token",
apiKey: "your API key",
});
To add an item to your index:
constructorio.addItem({
item_name: "power_drill",
section: "Products"
}, function(error, response) {
console.log(response);
});
To remove an item from your index:
constructorio.removeItem({
item_name: "power_drill",
section: "Products"
}, function(error, response) {
console.log(response);
});
To modify an item in your index:
constructorio.modifyItem({
item_name: "power_drill",
section: "Products",
url: "http://www.mysite.com/power_drill",
}, function(error, response) {
console.log(response);
});
To get autocomplete results:
const userParams = {
i: 'user device identifier',
s: 1
};
constructorio.getAutocompleteResults({
query: 'powe',
num_results: 4,
}, userParams, function(error, response) {
console.log(response);
});
To get search results:
const userParams = {
i: 'user device identifier',
s: 1
};
constructorio.getSearchResults({
query: 'power drill',
section: 'Products',
sort_by: 'relevance',
}, userParams, function(error, response) {
console.log(response);
});