Fetch API
Reference for haven.fetch methods. All methods use callbacks (not Promises).
Available after haven.init() completes and haven.ready() returns true.
Query types
The queryType parameter controls the API query:
| Type | API query_type | Description |
|---|---|---|
plugin | plugin-list | Optimized for embeds (recommended) |
name | name-list | Name-based listing (default fallback) |
ids | ids-list | Fetch by IDs |
Methods
getProducts(callback, queryType?, queryOptions?)
Fetch a list of products.
haven.fetch.getProducts(function (response) {
console.log(response);
}, 'plugin');
// With options
haven.fetch.getProducts(function (response) {
console.log(response);
}, 'plugin', { ids: [1234, 5678] });| Parameter | Type | Default | Description |
|---|---|---|---|
callback | function | required | Receives product array |
queryType | string | 'name' | Query type (see above) |
queryOptions | object | {} | Additional query parameters |
getEvents(callback, queryType?, queryOptions?)
Fetch a list of events.
haven.fetch.getEvents(function (response) {
console.log(response);
}, 'plugin');getProductsById(ids, callback, queryType?)
Fetch products by an array of IDs.
haven.fetch.getProductsById([1234, 5678], function (response) {
console.log(response);
}, 'plugin');getProductsByCategory(category, callback, queryType?)
Fetch products and category data. Callback receives [products, category].
haven.fetch.getProductsByCategory('CATEGORY_ID', function (response) {
var products = response[0];
var category = response[1];
}, 'plugin');getProductById(id, callback)
Fetch a single product by ID.
haven.fetch.getProductById(1234, function (response) {
console.log(response);
});getProductByNicename(nicename, callback)
Fetch a single product by URL nicename.
haven.fetch.getProductByNicename('my-business', function (response) {
console.log(response);
});getCategories(callback, ids?)
Fetch categories. Optionally filter by product category IDs.
haven.fetch.getCategories(function (response) {
console.log(response);
});
haven.fetch.getCategories(function (response) {
console.log(response);
}, ['CAT_ID_1', 'CAT_ID_2']);getCategoryById(id, callback)
haven.fetch.getCategoryById('CATEGORY_ID', function (response) {
console.log(response);
});getCategoryByNicename(nicename, callback)
haven.fetch.getCategoryByNicename('food-drink', function (response) {
console.log(response);
});getTypes(callback)
Fetch product types for filter dropdowns.
haven.fetch.getTypes(function (response) {
console.log(response);
});useParentFeedId(state?)
Switch API authentication to the parent feed ID.
haven.fetch.useParentFeedId(true);
haven.fetch.getProducts(function (response) {
// products from parent feed
}, 'plugin');
haven.fetch.useParentFeedId(false); // switch back| Parameter | Type | Default | Description |
|---|---|---|---|
state | boolean | false | Enable parent feed mode |
API endpoints
| Method | Endpoint |
|---|---|
getCategories | categories |
getCategoryById | categories/{id} |
getCategoryByNicename | categories?nicename= |
getTypes | types |
getProducts | product |
getEvents | events |
getProductById | product/{id} |
getProductByNicename | product?nicename= |
All requests include the haven-key header from your feed credentials.
Error handling
API errors are logged to the browser console. Always verify response is valid in your callback before passing to .render() or .init({ data }).