Product API Code Example
Description
If the online store does not contain grouped products, call retailrocket.products.post({}) in the product card and pass all product information.
If support for grouped products is required, use retailrocket.productsGroup.post({}).
Important: if there is a "quick view" of a product, the tracking code must also be called when this window is opened.
Code Example
- Without Grouped Products
- With Grouped Products
- Multi-language and Multi-currency
<script type="text/javascript">
(window["rrApiOnReady"] = window["rrApiOnReady"] || []).push(function() {
retailrocket.products.post({
"id": <product ID>,
"name": "Example product name",
"price": 777,
"pictureUrl": "http://example.com/path/to/Photo.jpg",
"url": "http://www.example.com/path/to/productPage",
"isAvailable": true,
"categoryPaths": ["Women/Clothes/Skirts","Women/New Arrivals"],
"description": "Some text description",
"vendor": "Brand name",
"model": "Model name",
"typePrefix": "Product type",
"oldPrice": 999,
"params": {
"<custom parameter 1 name>": "<custom parameter 1 value>",
"<custom parameter 2 name>": "<custom parameter 2 value>",
"<custom parameter N name>": "<custom parameter N value>"
}
});
rrApi.view(<product ID>);
});
</script>
<script type="text/javascript">
(window["rrApiOnReady"] = window["rrApiOnReady"] || []).push(function() {
retailrocket.productsGroup.post({
"groupId": <group ID>,
"name": "<string>",
"price": 777,
"pictureUrl": "http://example.com/path/to/Photo.jpg",
"url": "http://www.example.com/path/to/productPage",
"isAvailable": true,
"categoryPaths": ["Example/Category/Path","Another/Category"],
"description": "Some text description",
"products": {
"<product id>": {
"isAvailable": <bool>,
"name": "<string>",
"color": "<string>",
"size": "<string>",
"url": "<string>",
"pictureUrl": "<string>",
"price": <decimal>,
"oldPrice": <decimal>,
"description": "<string>",
"params": {
"<custom parameter 1 name>": "<custom parameter 1 value>",
"<custom parameter 2 name>": "<custom parameter 2 value>",
"<custom parameter N name>": "<custom parameter N value>"
}
},
"<product id>": {
"isAvailable": <bool>,
"name": "<string>",
"color": "<string>",
"size": "<string>",
"url": "<string>",
"pictureUrl": "<string>",
"price": <decimal>,
"oldPrice": <decimal>,
"description": "<string>",
"params": {
"<custom parameter 1 name>": "<custom parameter 1 value>",
"<custom parameter 2 name>": "<custom parameter 2 value>",
"<custom parameter N name>": "<custom parameter N value>"
}
}
},
"vendor": "Brand name",
"model": "Model name",
"typePrefix": "Product type",
"oldPrice": 999
});
rrApi.groupView([<product IDs>]);
});
</script>
<script type="text/javascript">
(window["rrApiOnReady"] = window["rrApiOnReady"] || []).push(function() {
retailrocket.products.post({
"id": <product ID>,
"name": "Example product name",
"price": 777,
"pictureUrl": "http://example.com/path/to/Photo.jpg",
"url": "http://www.example.com/path/to/productPage",
"isAvailable": true,
"categoryPaths": ["Women/Clothes/Skirts","Women/New Arrivals"],
"description": "Some text description",
"vendor": "Brand name",
"model": "Model name",
"typePrefix": "Product type",
"oldPrice": 999,
"params": {
"<custom parameter 1 name>": "<custom parameter 1 value>",
"<custom parameter 2 name>": "<custom parameter 2 value>",
"<custom parameter N name>": "<custom parameter N value>",
"languages": {
"<language1>": {
"description": "description in language1",
"name": "name in language1",
"url": "url to product in specific language",
"<custom parameter 1 name in language1>": "<custom parameter 1 value>",
"<custom parameter 2 name in language1>": "<custom parameter 2 value>",
"<custom parameter N name in language1>": "<custom parameter N value>"
},
"<language2>": {
"description": "description in language2",
"name": "name in language2",
"url": "url to product in specific language",
"<custom parameter 1 name in language2>": "<custom parameter 1 value>",
"<custom parameter 2 name in language2>": "<custom parameter 2 value>",
"<custom parameter N name in language2>": "<custom parameter N value>"
}
},
"currencies": {
"EUR": <price in EUR>,
"USD": <price in USD>
}
}
});
});
</script>
Required Product API Parameters without Grouped Products
| Parameter | Type | Description |
|---|---|---|
| id | integer | Unique product identifier, numbers only, up to 16 characters. Must not exceed 9,007,199,254,740,991. |
| name | string | Product name, up to 120 characters. It is better to specify the full unique name. |
| price | numerical | Price per unit, can be integer or fractional, not equal to zero. |
| url | string | Absolute link to the product page, up to 512 characters. |
| pictureUrl | string | Absolute link to the product image (jpeg/gif/png). Recommendation: ≤ 400×400 or ≤ 1 MB. Up to 512 characters. |
| isAvailable | bool | Availability status: true product is in stock, false not. Value is case-sensitive, use lowercase. |
| categoryPaths | string | Array of paths to low-level categories, separated by /. Paths must match the menu structure. For multiple categories, pass an array, for example ["Women/Clothes/Skirts","Women/New Arrivals"]. |
| description | string | Short description. For HTML, wrap in CDATA. No more than 200 characters. |
Required Product API Parameters with Grouped Products
| Parameter | Type | Description |
|---|---|---|
| products | JSON object | Contains all products of the group, each as a separate object. isAvailable is mandatory. Other fields, if absent, are taken from the general group parameters. |
| groupId | integer/string | Identifier for a group of variations of a single model. For non-grouped items, the offer identifier can be passed. |
Additional Parameters
| Parameter | Type | Description |
|---|---|---|
| vendor | string | Manufacturer or brand. Used in manufacturer-based recommendations. |
| oldPrice | number | Old price. Can be shown in recommendations or used to calculate discounts. |
| params | JSON object | Product characteristics. Up to 40 elements "<param name>": "<value>". Values can be used for filtering and displayed in widgets. |
Parameter for Regionality Support
| Parameter | Type | Description |
|---|---|---|
| stockId | string | User's region/warehouse/language identifier. Each region should have at least 5 times more unique visitors per month than the number of products in the region. |
Multi-language and Multi-currency Support
If the website allows users to choose from several languages and currencies, then additional parameters can be used to implement the same functionality in Retail Rocket products.
<script type="text/javascript">
(window["rrApiOnReady"] = window["rrApiOnReady"] || []).push(function() {
retailrocket.products.post({
"id": <product ID>,
"name": "Example product name",
"price": 777,
"pictureUrl": "http://example.com/path/to/Photo.jpg",
"url": "http://www.example.com/path/to/productPage",
"isAvailable": true,
"categoryPaths": ["Women/Clothes/Skirts","Women/New Arrivals"],
"description": "Some text description",
"vendor": "Brand name",
"model": "Model name",
"typePrefix": "Product type",
"oldPrice": 999,
"params": {
"<custom parameter 1 name>": "<custom parameter 1 value>",
"<custom parameter 2 name>": "<custom parameter 2 value>",
"<custom parameter N name>": "<custom parameter N value>",
"languages": {
"<language1>": {
"description": "description in language1",
"name": "name in language1",
"url": "url to product in specific language",
"<custom parameter 1 name in language1>": "<custom parameter 1 value>",
"<custom parameter 2 name in language1>": "<custom parameter 2 value>",
"<custom parameter N name in language1>": "<custom parameter N value>"
},
"<language2>": {
"description": "description in language2",
"name": "name in language2",
"url": "url to product in specific language",
"<custom parameter 1 name in language2>": "<custom parameter 1 value>",
"<custom parameter 2 name in language2>": "<custom parameter 2 value>",
"<custom parameter N name in language2>": "<custom parameter N value>"
}
},
"currencies": {
"EUR": <price in EUR>,
"USD": <price in USD>
}
}
});
});
</script>