Skip to content

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:

TypeAPI query_typeDescription
pluginplugin-listOptimized for embeds (recommended)
namename-listName-based listing (default fallback)
idsids-listFetch by IDs

Methods ​

getProducts(callback, queryType?, queryOptions?) ​

Fetch a list of products.

javascript
haven.fetch.getProducts(function (response) {
  console.log(response);
}, 'plugin');

// With options
haven.fetch.getProducts(function (response) {
  console.log(response);
}, 'plugin', { ids: [1234, 5678] });
ParameterTypeDefaultDescription
callbackfunctionrequiredReceives product array
queryTypestring'name'Query type (see above)
queryOptionsobject{}Additional query parameters

getEvents(callback, queryType?, queryOptions?) ​

Fetch a list of events.

javascript
haven.fetch.getEvents(function (response) {
  console.log(response);
}, 'plugin');

getProductsById(ids, callback, queryType?) ​

Fetch products by an array of IDs.

javascript
haven.fetch.getProductsById([1234, 5678], function (response) {
  console.log(response);
}, 'plugin');

getProductsByCategory(category, callback, queryType?) ​

Fetch products and category data. Callback receives [products, category].

javascript
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.

javascript
haven.fetch.getProductById(1234, function (response) {
  console.log(response);
});

getProductByNicename(nicename, callback) ​

Fetch a single product by URL nicename.

javascript
haven.fetch.getProductByNicename('my-business', function (response) {
  console.log(response);
});

getCategories(callback, ids?) ​

Fetch categories. Optionally filter by product category IDs.

javascript
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) ​

javascript
haven.fetch.getCategoryById('CATEGORY_ID', function (response) {
  console.log(response);
});

getCategoryByNicename(nicename, callback) ​

javascript
haven.fetch.getCategoryByNicename('food-drink', function (response) {
  console.log(response);
});

getTypes(callback) ​

Fetch product types for filter dropdowns.

javascript
haven.fetch.getTypes(function (response) {
  console.log(response);
});

useParentFeedId(state?) ​

Switch API authentication to the parent feed ID.

javascript
haven.fetch.useParentFeedId(true);
haven.fetch.getProducts(function (response) {
  // products from parent feed
}, 'plugin');

haven.fetch.useParentFeedId(false); // switch back
ParameterTypeDefaultDescription
statebooleanfalseEnable parent feed mode

API endpoints ​

MethodEndpoint
getCategoriescategories
getCategoryByIdcategories/{id}
getCategoryByNicenamecategories?nicename=
getTypestypes
getProductsproduct
getEventsevents
getProductByIdproduct/{id}
getProductByNicenameproduct?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 }).

Haven Destinations integration documentation