JS version of the ProductApi SDK to be used on the server and (eventually) client.
npm install opencommercesearch-ocs-sdk
Run style and unit tests once.
npm test
or
grunt test
Continuosly run style and unit tests while watching for changes.
grunt develop
All API methods make async requests and return promises which support .then() .done() and .fail() methods. Read more about promises here.
var productApiService = require('opencommercesearch-sdk-js');
productApiService.config({
host: 'api.domain.com'
});
productApiService
.searchProducts({
q: 'a search term',
site: 'your_site'
})
.then(function(data) {
// do something
});
Configures the service, best used at application startup.
Property Type Description host String the host to use for all requests, should only be set once during server start preview boolean whether or not to set the debug boolean exposes additional helper methods and logging for debug purposes
Returns the current configuration settings.
Available methods are grouped below by the type of item returned (product, category, etc). All methods accept a single options object requiring at least a site, and usually one or more additional properties. Additionally, there are several optional properties that can be passed to most endpoints:
-
fields --- all endpoints have default fields that can be overridden with a comma separated list of field names
- dot notation is supported for nested fields
brand.name
- during development
fields: '*'
can be used to return all fields but is not recommended for production - always request the least amount of data required
- dot notation is supported for nested fields
-
metadata --- (string) used to specify what metadata is returned and is useful for reducing the size of the request
- for a product search request where facets are not required, using
metadata: found
can significantly reduce the size of the response
- for a product search request where facets are not required, using
- limit --- (int) number of items to return, search/browse endpoints have a max limit of 40
- offset --- (int) number of items to offset, used for pagination on search/browse endpoints
- preview --- (boolean) whether or not to return results from the preview environment
- outlet --- (boolean) whether or not to return products/categories in outlet
- filterQueries --- (string) filters (facets) to apply to search/browse endpoints, values can be found in metadata.facets.filters.filterQueries
Returns the specified product(s). Multiple products can be requested at once by passing a comma-separated string or array of productIds.
Property Type Description productId String|Array one or more productIds site String site code
Returns all products that match the search query.
Property Type Description q String a search query site String site code
Returns all products belonging to a particular category.
Property Type Description categoryId String a single categoryId site String site code
Returns all products belonging to a particular brand.
Property Type Description brandId String a single brandId site String site code
Returns all products belonging to a particular brand and category.
Property Type Description brandId String a single brandId categoryId String a single categoryId site String site code
Returns products similar to the product specified.
Property Type Description productId String a single productId site String site code
Returns all generations of the product.
Property Type Description productId String a single productId site String site code
Returns products with brand and titles matching the query.
Property Type Description q String a search query site String site code
Returns the specified category.
Property Type Description categoryId String a single categoryId site String site code maxLevels Int (optional) the number of taxonomy levels, defaults to 1 maxChildren Int (optional) the number childCategories to return per taxonomy level, defaults to all
Returns the top level category taxonomy for the specified site. Use maxLevels: -1
to return the entire taxonomy (only as needed).
Property Type Description site String site code maxLevels Int (optional) the number of taxonomy levels, defaults to 1 maxChildren Int (optional) the number childCategories to return per taxonomy level, defaults to all
Returns all categories for the specified brand.
Property Type Description brandId String a single brandId site String site code
Returns categories with titles that substring match the query.
Property Type Description q String a search query site String site code
Returns the brand specified.
Property Type Description brandId String a single brandId site String site code
Returns all brands for the specified site.
Property Type Description site String site code
Returns all brands with names that substring match the query.
Property Type Description q String a search query site String site code
Returns all brands with at least one product in the specified category.
Property Type Description categoryId String a single categoryId site String site code
Returns suggestions for queries, products, brands, and categories that substring match the query.
Property Type Description q String a search query site String site code
Returns suggestions for user search term queries that substring match query.
Property Type Description q String a search query site String site code