### Start Hydrogen Development Server
Source: https://developers.rebuyengine.com/reference/shopify-hydrogen-installation
Command to start a local development server for a Shopify Hydrogen project. This allows for real-time testing of changes on localhost.
```shell
yarn dev
```
--------------------------------
### Get Recommended Products (JavaScript)
Source: https://developers.rebuyengine.com/reference/recommended
This snippet demonstrates how to fetch recommended products using the Rebuy Engine API with JavaScript. It shows how to construct the request URL with parameters and process the JSON response. This code requires a valid API key which is not included in this example.
```javascript
// https://rebuyengine.com/api/v1/products/recommended?key=dafd5187be5b5ada05f761e64d42fe082068912b&format=pretty
const requestParameters = new URLSearchParams({
format: "pretty"
});
fetch(`https://rebuyengine.com/api/v1/products/recommended?${requestParameters}`)
.then(response => response.json())
.then(data => console.log(data));
```
--------------------------------
### Get Top Sellers API Request (JavaScript)
Source: https://developers.rebuyengine.com/reference/top-sellers
This snippet demonstrates how to fetch top-selling products from the Rebuyengine API using JavaScript. It requires an API key and specifies the desired output format. The example uses `fetch` to make a GET request and logs the JSON response to the console.
```javascript
// https://rebuyengine.com/api/v1/products/top_sellers?key=dafd5187be5b5ada05f761e64d42fe082068912b&format=pretty
const requestParameters = new URLSearchParams({
format: "pretty"
});
fetch(`https://rebuyengine.com/api/installed?${requestParameters}`)
.then(response => response.json())
.then(data => console.log(data));
```
--------------------------------
### GET /websites/developers_rebuyengine/settings
Source: https://developers.rebuyengine.com/reference/settings
Retrieves all smart search settings configured for the shop.
```APIDOC
## GET /websites/developers_rebuyengine/settings
### Description
Returns all of your Smart Search settings for your shop.
### Method
GET
### Endpoint
/websites/developers_rebuyengine/settings
### Parameters
#### Query Parameters
#### Request Body
### Request Example
(No request body for GET requests)
### Response
#### Success Response (200)
- **settings** (object) - An object containing all smart search settings.
#### Response Example
```json
{
"settings": {
"search_enabled": true,
"suggestions_enabled": true,
"max_suggestions": 5
}
}
```
```
--------------------------------
### Test Smart Cart Switch to Subscription with Experiments.js
Source: https://developers.rebuyengine.com/reference/experiments-examples
This example demonstrates enabling the 'Switch to Subscription' feature for a specific Smart Cart using `RebuyExperiments.run()` with settings. It requires the Smart Cart ID and specifies `switch_to_subscription.enabled: true`. Ensure the feature is initially disabled in the Smart Cart settings.
```javascript
RebuyExperiments.run({
key: 'smart-cart-123',
settings: {
switch_to_subscription: {
enabled: true
}
}
})
```
--------------------------------
### Test New Smart Cart with Experiments.js
Source: https://developers.rebuyengine.com/reference/experiments-examples
This example shows how to test a new Smart Cart using `RebuyExperiments.run()`. It requires a Smart Cart ID and uses the 'new-cart-' prefix. Similar to legacy carts, ensure the Smart Cart is set up in the Rebuy admin.
```coffeescript
RebuyExperiments.run('new-cart-456'); // New Smart Cart prefix: 'new-cart-'
```
--------------------------------
### Pre-populate All Checkout Options (JavaScript)
Source: https://developers.rebuyengine.com/reference/shopify-permalinks-examples
A comprehensive example demonstrating how to use ShopifyPermalink to pre-populate various checkout fields including discount codes, customer email, shipping addresses, cart notes, marketing attribution, and sales channel tokens. It requires the ShopifyPermalink library and `window.Cart.items`.
```javascript
// Create a new ShopifyPermalink object
const Permalink = new ShopifyPermalink('https://example-brand.myshopify.com', window.Cart.items);
// Set the 'discount' option with a special code
Permalink.setOptions('discount', 'save20');
// Set the 'email' field with the customer's email address
Permalink.setOptions('email', 'john.doe@email.com');
// Set the 'shipping_address' field with the customer's shipping address
Permanlink.setOptions({
shipping_address: {
first_name: 'John',
last_name: 'Doe',
address1: '1234 Super Fake, Blvd',
city: 'San Diego',
zip: '92117'
}
});
// Set the cart 'attributes' with helpful tracking information
Permanlink.setOptions({
attributes: {
source: 'affiliate',
affiliate: 'Jane Doe'
}
});
// Set the cart 'notes' with additional helpful information
Permanlink.setOptions('note', 'Some custom note!');
// Set the cart 'ref' for marketing attribution
Permanlink.setOptions('ref', 'summer-sms-campaign');
// Set the 'access_token' to set Sales Channel attribution
Permanlink.setOptions('access_token', 'f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b');
// Log the checkout URL to the console
console.log(Permalink.url());
// Redirect the customer to checkout with all customer information fields pre-populated and a discount code auto-applied
Permanlink.go();
```
--------------------------------
### API Request Example - Search
Source: https://developers.rebuyengine.com/reference/smart-search
An example of a search request to the RebuyEngine API. It specifies the search term, fields to retrieve, sorting preferences, pagination settings, and filtering criteria.
```json
{
"searchTerm": "hat",
"fields": [
"product_id",
"name",
"price",
"tags",
"can_purchase",
"categories",
"compare_at_price",
"sku",
"visible",
"ratings",
"metafields"
],
"sortBy": {
"field": "price",
"order": "ASC"
},
"pageSize": 15,
"currentPage": 1,
"filters": {
...
}
}
```
--------------------------------
### Get Static Product Data (JavaScript)
Source: https://developers.rebuyengine.com/reference/static
This snippet demonstrates how to retrieve static product data using the Rebuyengine API. It constructs a GET request with product IDs and an API key. The response is a JSON object containing product details.
```javascript
// GET URL https://rebuyengine.com/api/v1/products/static?ids=###,###&key=dafd5187be5b5ada05f761e64d42fe082068912b&format=pretty
const requestParameters = new URLSearchParams({
ids: "###,###",
format: "pretty"
});
fetch(`https://rebuyengine.com/api/v1/products/static?${requestParameters}`)
.then(response => response.json())
.then(data => console.log(data));
```
--------------------------------
### GET /settings
Source: https://developers.rebuyengine.com/reference/settings
Retrieves all Smart Search settings for your shop, including global configurations and keyword-specific rules.
```APIDOC
## GET /settings
### Description
Returns all of your Smart Search settings for your shop.
### Method
GET
### Endpoint
/settings
#### Query Parameters
- **key** (string) - Optional - Your Rebuy public API key
#### Headers
- **Rebuy-Api-Key** (string) - Required - Your Rebuy public API key or My Shopify Domain
### Response
#### Success Response (200)
- **successful** (boolean) - Indicates if the request was successful.
- **data** (object) - Contains the shop's smart search settings.
- **globalSettings** (object) - Global search settings.
- **setting** (object) - Detailed global settings.
- **settingsId** (integer)
- **owner** (integer)
- **enabled** (boolean)
- **renderOos** (integer)
- **excludeOffensiveTerms** (boolean)
- **searchResultsPageUrl** (string)
- **excludedTerms** (array) - Array of excluded terms.
- **id** (integer)
- **term** (string)
- **excludedProductTags** (array) - Array of excluded product tags.
- **id** (integer)
- **tag** (string)
- **userDefinedCode** (array) - Array of user-defined code snippets.
- **id** (integer)
- **body** (string)
- **type** (string)
- **owner** (integer)
- **settingsId** (integer)
- **excludedProducts** (array)
- **excludedCollections** (array)
- **searchInfluence** (array)
- **keywordSettings** (object) - Keyword-specific search settings.
- **setting** (object) - Detailed keyword settings.
- **owner** (integer)
- **keywordGroups** (array) - Array of keyword groups.
- **id** (integer)
- **keywords** (array) - Array of keywords within the group.
- **id** (integer)
- **keyword** (string)
- **redirectUrl** (string)
- **redirectEnabled** (boolean)
- **keywordGroupName** (string)
- **keywordInfluence** (array)
- **promotedProducts** (array)
- **showPromotedBadge** (boolean)
- **promotedProductsAlwaysFirst** (boolean)
### Response Example
```json
{
"successful": true,
"data": {
"globalSettings": {
"setting": {
"settingsId": 18,
"owner": 6410,
"enabled": true,
"renderOos": 0,
"excludeOffensiveTerms": true,
"searchResultsPageUrl": "/search",
"excludedTerms": [
{
"id": 58,
"term": "Lasso"
},
{
"id": 59,
"term": "Roy"
}
],
"excludedProductTags": [
{
"id": 120,
"tag": "bad"
},
{
"id": 121,
"tag": "awful"
}
],
"userDefinedCode": [
{
"id": 1,
"body": ".rebuy-quick-view__container {\n background-color: aquamarine !important;\n}",
"type": "css",
"owner": 6410,
"settingsId": 18
}
],
"excludedProducts": [],
"excludedCollections": [],
"searchInfluence": []
}
},
"keywordSettings": {
"setting": {
"owner": 6410,
"keywordGroups": [
{
"id": 36,
"keywords": [
{
"id": 3828,
"keyword": "sound"
}
],
"redirectUrl": "/products/stay-sharp-brew",
"redirectEnabled": true,
"keywordGroupName": "Pop Ups",
"keywordInfluence": [],
"promotedProducts": [],
"showPromotedBadge": true,
"promotedProductsAlwaysFirst": true
},
{
"id": 37,
"keywords": [
{
"id": 108,
"keyword": "Add ons"
},
{
"id": 110,
"keyword": "addon"
},
{
"id": 111,
"keyword": "add on"
}
],
"redirectUrl": "",
"redirectEnabled": false,
"keywordGroupName": "AddOns",
"keywordInfluence": [],
"promotedProducts": [],
"showPromotedBadge": true,
"promotedProductsAlwaysFirst": true
},
{
"id": 38,
"keywords": [
{
"id": 109,
"keyword": "accessories"
}
],
"redirectUrl": "",
"redirectEnabled": false,
"keywordGroupName": "Accessories",
"keywordInfluence": [],
"promotedProducts": [],
"showPromotedBadge": true,
"promotedProductsAlwaysFirst": true
}
]
}
}
}
}
```
```
--------------------------------
### GET /products
Source: https://developers.rebuyengine.com/reference/trending-products
Retrieves a list of products available in the RebuyEngine platform. Supports filtering and pagination.
```APIDOC
## GET /products
### Description
Retrieves a list of products from the RebuyEngine platform. This endpoint can be used to fetch product details, including their IDs, titles, descriptions, pricing, and associated variants.
### Method
GET
### Endpoint
/products
### Query Parameters
- **limit** (integer) - Optional - The maximum number of products to return.
- **page** (integer) - Optional - The page number of results to retrieve.
### Request Example
```
GET /products?limit=10&page=1
```
### Response
#### Success Response (200)
- **data** (array) - An array of product objects.
- **id** (integer) - The unique identifier for the product.
- **title** (string) - The name of the product.
- **body_html** (string) - The HTML description of the product.
- **vendor** (string) - The vendor of the product.
- **product_type** (string) - The type of product.
- **created_at** (string) - The date and time the product was created.
- **handle** (string) - A URL-friendly identifier for the product.
- **updated_at** (string) - The date and time the product was last updated.
- **published_at** (string) - The date and time the product was published.
- **template_suffix** (string) - The suffix for the product's template.
- **tags** (string) - Comma-separated tags associated with the product.
- **published_scope** (string) - The scope in which the product is published.
- **admin_graphql_api_id** (string) - The GraphQL API ID for the product.
- **variants** (array) - An array of product variant objects.
- **id** (integer) - The unique identifier for the variant.
- **product_id** (integer) - The ID of the product this variant belongs to.
- **title** (string) - The name of the variant (e.g., color, size).
- **price** (string) - The price of the variant.
- **sku** (string) - The Stock Keeping Unit for the variant.
- **position** (integer) - The position of the variant.
- **inventory_policy** (string) - The inventory policy for the variant.
- **compare_at_price** (string) - The compare-at price for the variant.
- **fulfillment_service** (string) - The fulfillment service for the variant.
- **inventory_management** (object) - Information about inventory management for the variant.
#### Response Example
```json
{
"data": [
{
"id": 562361892900,
"title": "Flex Fleece Zip Hoodie",
"body_html": "Flex Fleece Zip Hoodie",
"vendor": "Example Brand",
"product_type": "",
"created_at": "2018-03-20T13:49:54-04:00",
"handle": "american-apparel-flex-fleece-zip-hoodie",
"updated_at": "2019-09-20T14:11:25-04:00",
"published_at": "2018-03-20T13:46:55-04:00",
"template_suffix": "",
"tags": "carthook_checkout, clothing",
"published_scope": "web",
"admin_graphql_api_id": "gid://shopify/Product/562361892900",
"variants": [
{
"id": 7162327597092,
"product_id": 562361892900,
"title": "Black",
"price": "36.00",
"sku": "AAFFZH-1",
"position": 1,
"inventory_policy": "deny",
"compare_at_price": "45.00",
"fulfillment_service": "manual",
"inventory_management": {},
"admin_graphql_api_id": "gid://shopify/ProductVariant/7162327597092"
}
]
}
]
}
```
```
--------------------------------
### GET /websites/developers_rebuyengine/product_list
Source: https://developers.rebuyengine.com/reference/smart-collections-product-list
Fetches a list of products filtered by Smart Collection and other request parameters.
```APIDOC
## GET /websites/developers_rebuyengine/product_list
### Description
Returns a list of products for a Smart Collection based on the given parameters in the request body. Only products within the specified collection are returned.
### Method
GET
### Endpoint
/websites/developers_rebuyengine/product_list
### Parameters
#### Query Parameters
None
#### Request Body
- **collection_id** (string) - Required - The ID of the Smart Collection to filter products by.
- **limit** (integer) - Optional - The maximum number of products to return.
- **offset** (integer) - Optional - The number of products to skip before starting to collect.
- **sort_by** (string) - Optional - The field to sort the products by (e.g., 'created_at', 'price').
- **sort_order** (string) - Optional - The order to sort the products in ('asc' or 'desc').
### Request Example
```json
{
"collection_id": "your_collection_id",
"limit": 10,
"offset": 0,
"sort_by": "price",
"sort_order": "asc"
}
```
### Response
#### Success Response (200)
- **products** (array) - A list of product objects.
- **product_id** (string) - The unique identifier for the product.
- **name** (string) - The name of the product.
- **price** (number) - The price of the product.
- **created_at** (string) - The timestamp when the product was created.
#### Response Example
```json
{
"products": [
{
"product_id": "prod_123",
"name": "Example Product",
"price": 19.99,
"created_at": "2023-10-27T10:00:00Z"
}
]
}
```
```
--------------------------------
### Shop Settings Configuration Example (JSON)
Source: https://developers.rebuyengine.com/reference/settings
This JSON object represents a successful retrieval of shop settings, including product configurations, editor layout options, and other customizable features. It serves as a template for understanding the expected structure of shop settings data.
```json
{
"products": [
{
"handle": "coffee",
"id": 36,
"name": "Coffee",
"visible": false,
"type": "custom",
"index": 3,
"limit": 1,
"enabled": true,
"collectionId": 373330870505
}
],
"editorLayout": {
"id": 8,
"layout": "dropdown",
"layoutMode": "left",
"soldOutTitle": "Sold Out",
"addToCartTitle": "Add to Cart",
"addToCartEnabled": true,
"addedToCartTitle": "Added!!!",
"addingToCartTitle": "Adding...",
"enabledProductRatings": true,
"matchingProductsTitle": "Matching Products",
"mobileColumnBreakpoint": 2,
"suggestedProductsTitle": "Showcase Recommended or Featured Products ",
"tabletColumnBreakpoint": 4,
"desktopColumnBreakpoint": 4,
"matchingProductsEnabled": true,
"autoCompleteTermsEnabled": true,
"matchingCollectionsTitle": "Matching Collections",
"suggestedProductsEnabled": true,
"suggestedCollectionsTitle": "Rebuy Smart Search: Featured Collections",
"suggestedSearchTermsTitle": "Add Suggested Search Terms To Improve Product Discovery",
"matchingCollectionsEnabled": true,
"searchByCollectionsEnabled": false,
"suggestedCollectionsEnabled": true,
"suggestedSearchTermsEnabled": true
}
}
```
--------------------------------
### Add Rebuy Product Recommendations Component
Source: https://developers.rebuyengine.com/reference/shopify-hydrogen-installation
Integrates the `RebuyProductRecommendations` component within a `RebuyWidgetContainer`. This setup allows fetching and displaying AI-powered product recommendations on your product pages. It requires a `product` object and a `dataSource` API endpoint.
```html
{/* REBUY: Product Recommendations */}
```
--------------------------------
### Get Installments Message HTML
Source: https://developers.rebuyengine.com/reference/smart-cart-methods-legacy
Retrieves an HTML string that provides click functionality for a specified installments provider, as configured in the Smart Cart admin settings.
```javascript
SmartCart.installmentsMessage();
```
--------------------------------
### Product Collection Configuration Example
Source: https://developers.rebuyengine.com/reference/smart-collections-active-setting
This JSON snippet illustrates the configuration for a product collection, specifying sorting parameters, collection details such as product IDs, and template settings like pagination and column breakpoints. It also defines text for UI elements like 'Add to Cart' and search bar placeholders.
```json
{
"filters": [
{
"name": "Name (Z-A)",
"index": 9,
"label": "",
"owner": 30210,
"enabled": false,
"settingsId": 3,
"lookbackType": "default",
"lookbackPeriod": 0
}
],
"collectionData": {
"createdAt": 1742390983,
"description": "",
"descriptionText": "",
"handle": "new-arrivals",
"id": "487577813288",
"images": [],
"name": "New Arrivals",
"productIds": [
"9530531873064",
"9530531741992",
"9530533413160",
"9530530922792",
"9530533216552",
"9530533282088",
"9530531545384",
"9530532036904",
"9530531971368",
"9530567786792",
"9530566934824",
"9530566803752",
"9530566639912",
"9530566476072",
"9530565755176",
"9530558087464",
"9530557858088",
"9530557759784",
"9530549469480",
"9530546520360",
"9530545668392",
"9530545635624",
"9530545209640",
"9530544619816",
"9530542719272",
"9530542358824",
"9530542031144",
"9530540982568",
"9530540687656",
"9530539999528",
"9530539868456",
"9530539475240",
"9530538950952",
"9530538852648",
"9530538623272",
"9530538524968",
"9530538295592",
"9530537804072",
"9530537607464",
"9530534297896"
],
"updatedAt": 1742390983,
"visible": true
},
"template": {
"layout": "sidebar",
"pageTitle": "Showing results for \"{term}\" ({count})",
"pagination": {
"type": "default",
"limitOptions": [
15,
25,
75
],
"loadMoreText": "Load More Products",
"amountPerPage": 15
},
"soldOutTitle": "Sold Out",
"addToCartTitle": "Add to Cart",
"addToCartEnabled": false,
"addedToCartTitle": "Added",
"addingToCartTitle": "Adding",
"enabledProductRatings": true,
"mobileColumnBreakpoint": 1,
"tabletColumnBreakpoint": 2,
"desktopColumnBreakpoint": 4,
"searchBarPlaceHolderText": "Search for products"
},
"tagFilters": [],
"tagExclusions": []
}
```
--------------------------------
### Install Rebuy Hydrogen Package
Source: https://developers.rebuyengine.com/reference/shopify-hydrogen-installation
Command to add the Rebuy Hydrogen package to your Shopify Hydrogen project. Ensure the development server is terminated before running this command.
```shell
yarn add @rebuy/rebuy-hydrogen
```
--------------------------------
### SmartCart Initialization
Source: https://developers.rebuyengine.com/reference/smart-cart-methods-base
Initializes the Smart Cart with provided settings.
```APIDOC
## `SmartCart.init`
### Description
Initializes the Smart Cart with provided settings.
### Method
`SmartCart.init(settings)`
### Parameters
#### Request Body
- **settings** (object) - Required - The Smart Cart settings object.
### Request Example
```javascript
Rebuy.SmartCart.init({
// ... settings object
});
```
```
--------------------------------
### Quick View Settings Configuration
Source: https://developers.rebuyengine.com/reference/settings
This snippet configures the 'quick view' feature for products. It specifies a settings ID, owner, an enabled flag, and a trigger selector for activating the quick view. This allows for a modal or pop-up display of product details without navigating away from the current page.
```json
{
"settingsId": 16,
"owner": 6410,
"enabled": true,
"triggerSelector": ""
}
```
--------------------------------
### GET /api/installed
Source: https://developers.rebuyengine.com/reference/top-sellers
This endpoint is used to retrieve information about installed applications or services. It accepts query parameters to filter and format the results.
```APIDOC
## GET /api/installed
### Description
Retrieves information about installed applications or services. This endpoint can be used to query for specific data points or a general overview of your Rebuyengine integration.
### Method
GET
### Endpoint
`/api/installed`
### Parameters
#### Query Parameters
- **format** (string) - Optional - Specifies the desired output format for the response (e.g., 'pretty').
### Request Example
```javascript
const requestParameters = new URLSearchParams({
format: "pretty"
});
fetch(`https://rebuyengine.com/api/installed?${requestParameters}`)
.then(response => response.json())
.then(data => console.log(data));
```
### Response
#### Success Response (200)
- **data** (object) - Contains the retrieved information about installed services.
#### Response Example
```json
{
"installed_services": [
{
"id": "service_123",
"name": "Example Service",
"version": "1.0.0"
}
]
}
```
```
--------------------------------
### Product Option Example Data Structure
Source: https://developers.rebuyengine.com/reference/viewed
This snippet details the structure for product options, such as color or size. It includes the option's name, position, and an array of possible values. This is fundamental for defining product variations.
```json
{
"name": {
"type": "string",
"example": "Color"
},
"position": {
"type": "integer",
"example": 1,
"default": 0
},
"values": {
"type": "array",
"items": {
"type": "string",
"example": "Black"
}
}
}
```
--------------------------------
### Configure Shopify Storefront in Hydrogen
Source: https://developers.rebuyengine.com/reference/shopify-hydrogen-installation
JavaScript configuration for a Hydrogen app, linking it to a Shopify storefront. Updates `storeDomain`, `storefrontToken`, and `storefrontApiVersion` in `hydrogen.config.js`.
```javascript
export default defineConfig({
shopify: {
defaultCountryCode: 'US',
defaultLanguageCode: 'EN',
storeDomain: 'YOUR_STORE_NAME.myshopify.com',
storefrontToken: 'YOUR_STOREFRONT_ACCESS_TOKEN',
storefrontApiVersion: '2022-07',
},
});
```
--------------------------------
### Configure Rebuy API Key in .env
Source: https://developers.rebuyengine.com/reference/shopify-hydrogen-installation
Configuration for the Rebuy + Hydrogen integration, specifying the public API key. This should be added to the `.env` file in the project root.
```toml
PUBLIC_REBUY_API_KEY=yourRebuyAPIKey
```
--------------------------------
### Get Item Product Tag Classes
Source: https://developers.rebuyengine.com/reference/smart-cart-methods-legacy
Returns a string of CSS classes derived from the product tags of a given item object. Each tag is prefixed with 'tag-'. Example: 'tag-available tag-best-seller'.
```javascript
SmartCart.itemProductTagsClasses(item);
```
--------------------------------
### Get Widget Instance
Source: https://developers.rebuyengine.com/reference/widget-settings
This snippet shows how to find a specific widget instance from the `window.Rebuy.widgets` array using its ID. This is a common starting point for manipulating widget settings.
```javascript
const widget = window.Rebuy.widgets.find((w) => w.id === "1234");
```
--------------------------------
### Create a New Hydrogen App
Source: https://developers.rebuyengine.com/reference/shopify-hydrogen-installation
Command to create a new Shopify Hydrogen project using a demo store template. Navigate to your working directory before running this command.
```shell
yarn create @shopify/hydrogen --template demo-store
```
--------------------------------
### Import and Use RebuyContextProvider in App.server.jsx
Source: https://developers.rebuyengine.com/reference/shopify-hydrogen-installation
React JSX code for integrating the RebuyContextProvider in a Shopify Hydrogen application. This wraps routing components to provide necessary context for Rebuy API calls.
```javascript
import {RebuyContextProvider} from '@rebuy/rebuy-hydrogen/RebuyContextProvider.client';
```
```html
} />
```
--------------------------------
### Run Experiment
Source: https://developers.rebuyengine.com/reference/experiments-methods
Runs an experiment and applies the provided changes immediately. It can target experiments by string identifier or a configuration object.
```APIDOC
## run
### Description
Runs an experiment and applies the provided changes immediately. This method accepts two arguments `experiment` and `useCookie`.
### Method
`run(experiment, useCookie)`
### Endpoint
N/A (Client-side method)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **experiment** (string | object) - Required. A string identifying an object to enable (e.g., 'smart cart' or '12345'). Alternatively, an object with `key` (string) and `settings` (object) properties.
- **useCookie** (boolean) - Optional. Boolean flag to use a session-based cookie for automatic application on subsequent page loads. Defaults to `false`.
### Request Example
```javascript
// Example with string identifier
RebuyExperiments.run('smart cart');
// Example with object configuration
RebuyExperiments.run({
key: 'smart cart',
settings: {
// modification settings
}
}, true);
```
### Response
#### Success Response (200)
N/A (This is a client-side method that applies changes directly)
#### Response Example
N/A
```
--------------------------------
### Open Quick View Interface
Source: https://developers.rebuyengine.com/reference/methods-1
The `openQuickView` method initiates the quick view search interface. It manages focus, tracks search sessions, and is typically triggered by a user event.
```javascript
openQuickView(event) {
// Opens the quick view search interface, sets focus, and triggers search session tracking.
}
```
--------------------------------
### Add Rebuy Recently Viewed Products Component
Source: https://developers.rebuyengine.com/reference/shopify-hydrogen-installation
Adds the `RebuyRecentlyViewedProducts` and `RebuyProductViewed` components to your product pages. The `RebuyWidgetContainer` fetches recently viewed product data, while `RebuyProductViewed` tracks user browsing history, powering real-time updates.
```html
{/* REBUY: Recently Viewed Products */}
```
--------------------------------
### Initialize Smart Cart
Source: https://developers.rebuyengine.com/reference/smart-cart-methods-legacy
Initializes the Smart Cart with provided settings. This method should be called before using other Smart Cart functionalities.
```javascript
SmartCart.init(settings);
```
--------------------------------
### Import Rebuy Components in Shopify Hydrogen
Source: https://developers.rebuyengine.com/reference/shopify-hydrogen-installation
Imports various Rebuy client components, including those for product recommendations, viewed products, recently viewed products, and a widget container for data fetching. These are essential for integrating Rebuy's features into your Hydrogen storefront.
```javascript
import {RebuyProductRecommendations} from '@rebuy/rebuy-hydrogen/RebuyProductRecommendations.client';
import {RebuyProductViewed} from '@rebuy/rebuy-hydrogen/RebuyProductViewed.client';
import {RebuyRecentlyViewedProducts} from '@rebuy/rebuy-hydrogen/RebuyRecentlyViewedProducts.client';
import {RebuyWidgetContainer} from '@rebuy/rebuy-hydrogen/RebuyWidgetContainer.client';
```
--------------------------------
### GET /api/v1/products/recommended
Source: https://developers.rebuyengine.com/reference/recommended
Retrieves recommended products. This endpoint allows you to get product recommendations based on various criteria.
```APIDOC
## GET /api/v1/products/recommended
### Description
Retrieves recommended products. This endpoint allows you to get product recommendations based on various criteria.
### Method
GET
### Endpoint
/api/v1/products/recommended
### Parameters
#### Query Parameters
- **key** (string) - Required - Your unique API key for authentication.
- **format** (string) - Optional - Specifies the output format. Accepted values are 'pretty' or 'json'. Defaults to 'json'.
### Request Example
```
GET https://rebuyengine.com/api/v1/products/recommended?key=YOUR_API_KEY&format=pretty
```
### Response
#### Success Response (200)
- **products** (array) - A list of recommended products.
- **product_id** (string) - The ID of the recommended product.
- **name** (string) - The name of the recommended product.
- **url** (string) - The URL of the recommended product.
- **image_url** (string) - The URL of the recommended product's image.
- **price** (string) - The price of the recommended product.
#### Response Example
```json
{
"products": [
{
"product_id": "12345",
"name": "Example Product",
"url": "https://rebuyengine.com/product/example",
"image_url": "https://rebuyengine.com/images/example.jpg",
"price": "$19.99"
}
]
}
```
#### Error Response (400/401)
- **error** (string) - Describes the error encountered (e.g., "Invalid key").
#### Error Response Example
```json
{
"error": "Invalid key"
}
```
```
--------------------------------
### Mount Component and Set Up Event Handlers
Source: https://developers.rebuyengine.com/reference/methods-1
The `mounted` lifecycle method is responsible for setting up various event listeners and DOM manipulations after the component has been mounted. This includes click listeners for search triggers, adjusting dropdown height, and initializing overlay functionality.
```javascript
mounted() {
// Sets up click event listeners for search triggers, adjusts dropdown height, and initializes overlay functionality.
}
```
--------------------------------
### Configure Keywords for Coffee Products
Source: https://developers.rebuyengine.com/reference/settings
This configuration defines keywords relevant to coffee, such as 'brew', 'coffee', 'espresso', and 'roast'. It also includes settings for redirect and promotion display.
```JSON
{
"id": 43,
"keywords": [
{
"id": 349,
"keyword": "brew"
},
{
"id": 350,
"keyword": "coffee"
},
{
"id": 351,
"keyword": "espresso"
},
{
"id": 352,
"keyword": "roast"
}
],
"redirectUrl": "",
"redirectEnabled": false,
"keywordGroupName": "Coffee",
"keywordInfluence": [],
"promotedProducts": [],
"showPromotedBadge": true,
"promotedProductsAlwaysFirst": true
```
--------------------------------
### Check if Installments are Enabled
Source: https://developers.rebuyengine.com/reference/smart-cart-methods-legacy
Checks if the 'payment installments' setting is enabled for the merchant in the Smart Cart admin settings. Returns a boolean.
```javascript
SmartCart.installmentsEnabled();
```
--------------------------------
### Fetch Similar Products using Rebuyengine API (JavaScript)
Source: https://developers.rebuyengine.com/reference/similar-products
This snippet demonstrates how to fetch similar products using the Rebuyengine API. It constructs a URL with product ID and limit parameters, then uses the fetch API to make the request and log the JSON response. Ensure you have a valid API key and Shopify product ID.
```javascript
// https://rebuyengine.com/api/v1/products/similar_products?key=dafd5187be5b5ada05f761e64d42fe082068912b&format=pretty
const requestParameters = new URLSearchParams({
shopify_product_id: "",
limit: "5"
});
fetch(`https://rebuyengine.com/api/v1/products/similar_products?${requestParameters}`)
.then(response => response.json())
.then(data => console.log(data));
```
--------------------------------
### Product Image Example Data Structure
Source: https://developers.rebuyengine.com/reference/viewed
This snippet outlines the structure for representing product images, including their ID, associated product ID, position, creation and update timestamps, dimensions (width and height), image source URL, and variant IDs. It's useful for managing and displaying product visuals.
```json
{
"id": {
"type": "integer",
"example": 2155921604644,
"default": 0
},
"product_id": {
"type": "integer",
"example": 562396463140,
"default": 0
},
"position": {
"type": "integer",
"example": 1,
"default": 0
},
"created_at": {
"type": "string",
"example": "2018-03-20T14:09:55-04:00"
},
"updated_at": {
"type": "string",
"example": "2019-11-15T23:59:45-05:00"
},
"alt": {},
"width": {
"type": "integer",
"example": 1528,
"default": 0
},
"height": {
"type": "integer",
"example": 1528,
"default": 0
},
"src": {
"type": "string",
"example": "https://cdn.shopify.com/s/files/1/0011/0746/0132/products/Anvil_Tri-Blend_Full_Zip_T-shirt_Hoodie-black-A.png?v=1573880385"
},
"variant_ids": {
"type": "array",
"items": {
"type": "integer",
"example": 7162489372708,
"default": 0
}
},
"admin_graphql_api_id": {
"type": "string",
"example": "gid://shopify/ProductImage/2155921604644"
}
}
```
--------------------------------
### Configure Payment Installments
Source: https://developers.rebuyengine.com/reference/settings-new
Access settings for displaying payment installment information, such as cost per payment for providers like AfterPay. Includes a URL for the terms of service.
```javascript
SmartCart.settings.installments;
```
--------------------------------
### SmartCart.getCheckoutSettings
Source: https://developers.rebuyengine.com/reference/smart-cart-methods-checkout-area
gets the checkout settings from the SmartCart.
```APIDOC
## SmartCart.getCheckoutSettings
### Description
Gets the checkout settings from the SmartCart.
### Method
Not specified (likely a client-side method)
### Endpoint
Not applicable (client-side method)
### Parameters
None
### Request Example
None
### Response
#### Success Response (object)
- **settings** (object) - An object containing checkout settings.
#### Response Example
```json
{
"settings": {
"theme": "dark",
"button_color": "#007bff"
}
}
```
```