JavaScript API
Allows you to use some public functions of the Unet API via JavaScript. Before you can use it, you need to enable the JavaScript API in the Business Settings section of the website for which you want to access data. This will give you the API key and you will need to specify a list of site domains for which access is enabled.
+Loading the Script
The library script must be loaded using the URL "https://static.unet.io/www/jslibs/siteapi.min.js".
Example:
<script src="https://static.unet.io/www/jslibs/siteapi.min.js"></script>
For debugging purposes you can use the unpacked version.
+Initialization
The API functions are implemented through an object of the UnetAPI class, which can be created in two ways:
1. By calling the constructor
var api = new UnetAPI(apikey, [options]);
Parameters
- apikey
The string that is the API access key for a particular site or several sites. This key can be generated in the Business settings section of your site or profile in Unet. Each key has a list of external site domains from which it is allowed to be used.
- options (optional)
An optional object with additional parameters for the object being created:
- onCartUpdate - a function like function(action, productIds, api), which must be called whenever the contents of the Cart are modified. The action parameter contains a string with the action code performed over the Cart: "append", "replace", "remove", "clear". productIds is array of IDs of products which changed their state in the Cart. In this function you should redraw the contents of the Cart and also can refraw the view of involved products to depict their cart-related state (e.g. show the "Add to Cart"/"Remove from Cart" buttons).
- lang - 2-letter code of language to be used for several localization-dependent functions, e.g. unitName(). If you preload or preconfigure language manually, it will be selected by default. Otherwise requested (or English by default) language will be loaded dynamically. Unet currently provides: en (English), ru (Russian), uk (Ukrainian). Custom language code is allowed if correct structure of global variable _uSigns for that language exists at the time of constructor call.
- plugins - object with plugin configurations, to simplify your API usage experience
Example:
var unet_api = new UnetAPI("YOUR_API_KEY",{
lang:'en',
onCartUpdate:function(act,prod_ids){
console.log('Cart updated!',act,prod_ids);
},
onLoadError:function(){
console.error('Error loading requisites!');
},
plugins:{
sidecart:{
theme: 'auto',
place: 'left',
use_minimized_cart: true
}
}
});
Plugins
- sidecart
- position - position of the cart ('left', 'right'). Default: left
- theme - design of the cart ('light', 'dark', 'auto'). Default: light
- title - title for the cart. Default: Shopping cart (based on the selected language)
- use_minimized_cart - flag to show the minimized version of the shopping cart. Default: true
- zindex - z-index of top cart object. Default: 1000
Exceptions
- "invalid_apikey" string
Appears if apikey has an invalid type or value that does not match the format.
Localization (manual mode)
Before loading the library script it is possible to load a language file (it has Javascript form) for one or several languages. This is optional if Unet-provided language is used and API is initialized in synchronous SCRIPT element, in such case necessary language is loaded automatically in a sync manner so that language-dependent text labels will be already available in following SCRIPT elements or in BODY.onload handler.
URL of Unet-provided language file has the form like "https://static.unet.io/www/jslibs/lang_LNGCODE.js", where LNGCODE is 2-letter language code in lowercase.
The list of supported languages is described above at the Initialization section.
It is also possible to provide own language file for any language.
2. By calling the static method UnetAPI.get()
var api = UnetAPI.get( [apikey, [ options] ]);
Returns either a new or previously created object with the specified apikey. Also, unlike the constructor, this method does not throw exceptions in case of errors.
Parameters
- apikey (optional)
Similar to the UnetAPI constructor parameter, but allows any false value as a requirement to return the first UnetAPI object created, or null if none was created. If false, it searches for an object with the specified 'apikey'. If successful, the found object is returned, otherwise the constructor is called with 'apikey' and 'options' passed in.
- options (optional)
Similar to the UnetAPI constructor parameter, but only used when creating a new object.
Returned value
UnetAPI class object, or null in case of an error creating a new object or finding a previously created one.
+UnetAPI class object methods
getProductList( [options[, timeout[, abortCtrl ] ] ] )
Gets data from the product page.
Parameters
- options (optional)
Object with the parameters of the desired list of products:
- type - string, optional filter on the type of returned goods. By default, items of type "product" and "service" are returned.
Possible values: 'product', 'service', 'event', 'campaign', 'digital'.
- cursor - cursor string indicating the page from which you want to continue returning the list of items. Any false value indicates the beginning of the list. Cursors for the next and/or previous product pages will be returned in the response, which allows you to organize multipage product list navigation (with optional filter) in "previous page, next page" style or with automatic loading of the next page.
- limit - an integer between 1 and 100, indicating the desired number of items on the page. By default it is 25.
- timeout (optional)
A positive number with the maximum wait time for the query result, in milliseconds. By default or when an invalid value is specified, the timeout is left up to the browser or can be implemented using the abortCtrl parameter.
- abortCtrl (optional)
An object of AbortController class. Its abort() method can be used to interrupt query execution. If a valid value for the timeout parameter was also specified, this provided object will be used to implement the timeout (in such case an object of class UnetApiError with code equal to 'request_timeout' will be stored in the abortCtrl object under the '_reason' key).
Returned value
Promise which, if successful, resolves into an object of the ProductListResult class. In case of runtime error, request error or if the API server refuses to return the result, Promise will be rejected. In this case, if an error is handled by this library, its format passed to the catch block will correspond to the UnetApiError class.
getProductItems( ids[, timeout[, abortCtrl ] ] )
Gets data about the products from the list of their identifiers.
Parameters
- ids (required)
An array of product identifiers. A value that is not an array is treated as an array of one element with that value.
- timeout (optional)
A positive number with the maximum wait time for the query result, in milliseconds. By default or when an invalid value is specified, the timeout is left up to the browser or can be implemented using the abortCtrl parameter.
- abortCtrl (optional)
An object of AbortController class. Its abort() method can be used to interrupt query execution. If a valid value for the timeout parameter was also specified, this provided object will be used to implement the timeout (in such case an object of class UnetApiError with code equal to 'request_timeout' will be stored in the abortCtrl object under the '_reason' key).
Returned value
Promise which, except in some cases of runtime errors, is always resolved successfully to an object that contains the key for each unique value from the ids parameter, and in the value either an object of the ProductData class or UnetApiError.
getProduct( id[, timeout[, abortCtrl ] ] )
Gets data about the product by its identifier.
Parameters
- id (required)
Product's identifier.
- timeout (optional)
A positive number with the maximum wait time for the query result, in milliseconds. By default or when an invalid value is specified, the timeout is left up to the browser or can be implemented using the abortCtrl parameter.
- abortCtrl (optional)
An object of AbortController class. Its abort() method can be used to interrupt query execution. If a valid value for the timeout parameter was also specified, this provided object will be used to implement the timeout (in such case an object of class UnetApiError with code equal to 'request_timeout' will be stored in the abortCtrl object under the '_reason' key).
Returned values
Promise which, if successful, resolves into an object of the ProductData class. In case of runtime error, request error or if the API server refuses to return the result, Promise will be rejected. In this case, if the error is handled by this library, its format passed to the catch will correspond to the UnetApiError class.
preloadProductList( options, callback[, async[, timeout ] ])
Gets data on product page, but, unlike getProductList() method, allows to do it synchronously, at the initial processing stage of HTML-page. This requires leaving async parameter false and calling this method from synchronous SCRIPT element (with embedded Javascript code or with loadable code but without "async" or "defer" attributes). This technique will increase time to the initial display of the page to the customer and, in general, is not recommended, but in some cases allows you to use a simpler technique to develop the site. The asynchronous mode of this method, again unlike getProductList(), allows you to get the result without using Promise, into "classic" callback. The transport protocol in either mode is JSONP, which requires browser support for "crossorigin" attribute for SCRIPT element, which makes the method unsuitable for Internet Explorer browser.
Parameters:
- options (required)
Object with the parameters of the desired list of products:
- type - string, optional filter on the type of returned goods. By default all product types are returned.
Possible values: 'product', 'service', 'event', 'campaign', 'digital'
- cursor - cursor string indicating the page from which you want to continue returning the list of items. Any false value indicates the beginning of the list. Cursors for the next and/or previous product pages will be returned in the response, which allows you to organize multipage product list navigation (with optional filter) in "previous page, next page" style or with automatic loading of the next page.
- limit - an integer between 1 and 100, indicating the desired number of items on the page. By default it is 25.
- callback (required)
A function like function(result) in which the result of a request to the products page will be passed. The result argument is always an object. The 'error' key in it indicates that it is an object of class UnetApiError. In case of success, result will contain an object of ProductListResult class.
- async (optional)
Flag whose true value selects the asynchronous mode of the function. Otherwise the synchronous mode is used.
- timeout (optional)
A number with the maximum query result waiting time, in milliseconds. Values from 1 to 60000 are allowed. The default is 30000ms.
Returned values
True if the remote request is in progress and the callback will be called later. False if there was an error before the request was sent or if all requested products are already in the cache. In synchronous mode a returned value of false also means that the callback has already been called.
preloadProductItems( ids[, callback[, async[, timeout ] ] ])
Gets data about products according to their identifiers list, but, unlike getProductItems() method, allows to do it synchronously, at the initial processing stage of HTML-page. This requires leaving async parameter false and calling method from synchronous SCRIPT element (with embedded Javascript code or with loadable code but without "async" or "defer" attributes). This technique will increase time to the initial display of the page to the customer and, in general, is not recommended, but in some cases allows you to use a simpler technique to develop the site. The asynchronous mode of this method, again unlike getProductItems(), allows you to get the result without using Promise, into "classic" callback. The transport protocol in either mode is JSONP, which requires browser support for "crossorigin" attribute for SCRIPT element, which makes the method unsuitable for Internet Explorer browser.
Parameters
- ids (required)
An array of product identifiers. A value that is not an array is treated as an array of one element with that value.
- callback (optional)
A function like function(result), which will be passed an object that contains a key for each unique value from the ids parameter, and in the value either an object of class ProductData or UnetApiError.
- async (optional)
Flag whose true value selects the asynchronous mode of the function. Otherwise the synchronous mode is used.
- timeout (optional)
A number with the maximum query result waiting time, in milliseconds. Values from 1 to 60000 are allowed. The default is 30000ms.
Returned values
True if the remote request is in progress and the callback will be called later. False if there was an error before the request was sent or if all requested products are already in the cache. In synchronous mode a returned value of false also means that the callback has already been called.
cartAction( action[, item[, options ] ])
Performs an action on the contents of the Cart.
Parameters
- action (required)
A string with code of the desired action:
- clear - clear the Cart, the item parameter is omitted
- add - add product to the Cart, and if such product item is already present, increase the quantity
- replace - add product to the Cart, replacing an existing similar product.
- remove - remove product item or several items of the same product from the Cart or decrease the quantity of specific item.
- item (optional)
An object with exact of generalized information about the product being added or removed:
- product_id - integer required
Product identifier.
- price_id - string optional
If the product has price options, it is required to specify the identifier of the desired price option for add and replace actions. For remove action null/undefined value in this field for a product with price options means "any price option".
- alt_price - number optional
The alternative price in cents of the store's base currency if it is allowed for the product and a buyer has set it.
- quantity - number optional
The number of items if the item is a quantity one. Set to 1 by default for add and replace actions. For remove action null/undefined value in this field means "all quantity of the product". For add and remove actions numeric value of this field (null/undefined for add is changed into 1) means to increment or decrement the quantity correspondingly. For such effect it is also required to specify valid price_id and attributes if appropriate.
- attributes - object optional
If the product has attributes, it is required to specify values for all of them as an object with attribute IDs in the keys and corresponding attribute value IDs in the values. For remove action null/undefined value in this field for a product with attributes means "any set of attributes".
- options (optional)
An object with additional parameters for requested action:
- no_save - boolean optional
Flag with true value meaning that the modified cart must not be saved to Local Storage.
- pos - string optional
Names the position where new item must be added by add or replace action: 'first', 'last' (default).
Returned value
True if the cart contents was changed, otherwise false. In former case the onCartUpdate callback will be called before this function returns.
probeCartAction( item )
Probes for possible action for cartAction() call and current Cart-related status for provided exact of generalized product specification.
Parameters
- item (required)
An object with information about the product being probed:
- product_id - integer required
Product identifier.
- price_id - string optional
Identifier of price option or value 'alt' (if alt_price also provided). Can and in some cases must be provided if the product has price options. In particular, it is required for add and replace actions to succeed. null/undefined value in this field for a product with price options means "any price option", i.e. generalized product specification.
- alt_price - number optional
The alternative price in cents of the store's base currency if it is allowed for the product and a buyer has set it. price_id must be set to string 'alt'.
- attributes - object optional
An object with attribute IDs in the keys and corresponding attribute value IDs in the values. Can and in some cases must be provided if the product has attributes. In particular, it is required for add and replace actions to succeed. null/undefined value in this field for a product with attributes means "any set of attributes", i.e. generalized product specification.
Returned value
Object with indication of all possible actions or errors which unable specific actions, some details about instances of requested product in the Cart:
- can_remove - integer optional
Positive value of this field shows how many Cart items matching item argument can be removed by cartAction() with remove action.
- remove_error - string optional
In case if provided arguments are erroneous for the remove action, contains error code. Possible errors: 'invalid_arguments' (mandatory product_id field is missing).
- can_add - number optional
Positive value of this field shows how much quantity of product matching item argument can be added by cartAction() with add action. This implies the check of the maximum quantity the product has in the Cart according to the max QuantityConfig property.
- add_error - string optional
In case if provided arguments are erroneous for the add action, contains error code. Possible errors: 'invalid_arguments' (mandatory product_id field is missing), 'invalid_price_id', 'price_id_required', 'invalid_attribute_value', 'attribute_value_required'.
- can_replace - integer optional
Positive value of this field shows how many Cart items matching item argument will be replaced (i.e. removed) by cartAction() with replace action or add (if it is allowed in its turn). New Cart item can replace one or several existing items according to price_model and attributes_model fields of ProductData. Products without price options or attributes can have single instance in the Cart.
- replace_error - string optional
In case if provided arguments are erroneous for the replace action, contains error code. Possible errors: 'invalid_arguments' (mandatory product_id field is missing), 'invalid_price_id', 'price_id_required', 'invalid_attribute_value', 'attribute_value_required'.
- quantity - number optional
Current quantity of the specified exact product in the Cart, if any. Usually, can_add will be positive also, unless maximum quantity of product for an order is reached.
- rest_quantity - number optional
Non-null value means the rest quantity of the specified exact product according to shop data. Zero and even negative values are valid here.
getCartProductIds( )
Gets a list of products IDs in the Cart. List is not unique, it's length and order corresponds to Cart items.
Returned values
Array of product IDs, possibly empty.
getCartItems( [timeout[, abortCtrl ] ] )
Gets a list of items in the cart along with the total amount payable.
Parameters
- timeout (optional)
A positive number with the maximum wait time for the query result, in milliseconds. By default or when an invalid value is specified, the timeout is left up to the browser or can be implemented using the abortCtrl parameter.
- abortCtrl (optional)
An object of AbortController class. Its abort() method can be used to interrupt query execution. If a valid value for the timeout parameter was also specified, this provided object will be used to implement the timeout (in such case an object of class UnetApiError with code equal to 'request_timeout' will be stored in the abortCtrl object under the '_reason' key).
Returned values
Promise which, if successful, resolves into an object of CartContent class. In case of runtime error, request error or if the API server refuses to return the result, Promise will be rejected. In this case, if the error is handled by this library, its format passed to the catch will correspond to the UnetApiError class.
buildCartPayUrl( [ options ] )
Returns the URL to which have to send the customer to pay for the cart. You can open the returned URL in the current browser window or in a new browser window.
Parameters:
- options (optional)
An object with the parameters for the payment process:
- redirect_path - an optional path to be appended to the domain of the current site to build a return URL for returning when the checkout is complete. By default the path '/' will be used. The '_unetapiact' parameter will also be added to the final, which will be processed by this library and cut out of the address automatically at the time of creating the access object to this API for the same apikey.
Returned value
A string with the URL to which the buyer must be sent to pay for the cart. If the cart is empty, null will be returned.
getShopInfo( nowait[, timeout[, abortCtrl ] ] )
Gets data about the shop.
Parameters
- nowait (optional)
A flag whose true value indicates that the response should be returned synchronously (timeout and abortCtrl are ignored), otherwise Promise is returned.
- timeout (optional)
A positive number with the maximum wait time for the query result, in milliseconds. By default or when an invalid value is specified, the timeout is left up to the browser or can be implemented using the abortCtrl parameter.
- abortCtrl (optional)
An object of AbortController class. Its abort() method can be used to interrupt query execution. If a valid value for the timeout parameter was also specified, this provided object will be used to implement the timeout (in such case an object of class UnetApiError with code equal to 'request_timeout' will be stored in the abortCtrl object under the '_reason' key).
Returned value
A false nowait returns Promise, which, if successful, resolves into an object of the ShopInfo class. In case of runtime error, request error or refusal of the API-server to return the result, Promise will be rejected. In this case, if the error is handled by the given library, its format passed to the catch will correspond to the UnetApiError class. A true nowait will return an object of class ShopInfo, if the data was obtained earlier, otherwise - null. The data about shop is loaded automatically when using any preloadSOMETHING or getSOMETHING method, except the currency methods (getBaseCurrencyCode, getDefCurrency, getCurrencies).
getDefCurrency( )
Gets the properties of the current default currency.
Parameters
None.
Returned value
An object of class currencyInfo. An empty object will be returned if the data about shop is not loaded yet and the setDefCurrency() method was not used.
getBaseCurrencyCode( )
Gets the three-letter code of base shop currency or null if store data has not yet been loaded.
Parameters
None.
Returned value
A string with the three-letter store base currency code, or null if the data about shop has not yet been loaded.
getCurrencies( )
Returns an object with all allowed shop currencies.
Parameters
None.
Returned value
An object, the keys of which are three-letter currency codes and the values are objects of class currencyInfo. null will be returned if data of the shop is not loaded yet and setDefCurrency() method was not used.
setDefCurrency( [curr] )
Allows you to select or set default currency properties.
Parameters
- curr (optional)
Depending on the value selects from the shop currencies or sets the properties of default currency:
- object with id field - assumed to be object of currencyInfo class, which sets all properties of default currency.
- string with currency code - sets the specified currency as default currency if the specified code is found in the object returned by getCurrencies() method.
- false value - sets the base shop currency as the default if no default currency is currently set.
Returned value
True if the default currency was set successfully, false if it could not be set.
Returns a string with the formatted amount of money.
unitName ( unitID [, quantity, shortFormat ] )
Returns a string with the unit name, e.g: items, kilograms, inches, pounds.
Parameters
- cents (required)
The amount in cents of some currency defined by the currency and convert values in the options object: in the convert mode the amount in the base currency of the store is assumed here, otherwise the currency is specified in the currency parameter.
- options (optional)
An object with parameters:
- currency - output currency: three-letter currency code (must be in getCurrencies() response) or object of currencyInfo class. In conversion mode (the convert parameter is true), the default is the currency returned by getDefCurrency(), and otherwise the shop base currency returned by getBaseCurrencyCode().
- convert - the flag indicating whether the cents amount should be converted from the shop base currency to the currency currency.
- locale - the locale for formatting the amount. By default this is the shop locale or 'en-US' if the shop properties are not loaded.
- show_zero - flag indicating that zero cents should be displayed (for example, '$ 1.00' vs '$ 1').
- show_plus - flag that a positive amount should have an explicit "+" at the beginning.
- show_exact - flag that cents can be fractional and should not be rounded so that a fractional amount of currency can be accurately displayed (e.g., show currency rate or price with fractional pennies). Can also have an integer value greater than 3 to indicate the total number of significant digits in the total, otherwise 9 significant digits are assumed.
Returned value
A line with the formatted amount of currency or "NaN" in case of error (incorrect arguments or lack of necessary store data).
+Data object classes
ProductListResult object
- items - array of ProductData always
Array of product data.
- limit - integer always
The requested number of products on the page.
- total_count - integer always
The total number of products that satisfy the filter.
- next_cursor - string optional
The value of cursor parameter to get the next page of the list of products, if the end of the list is not reached.
- prev_cursor - string optional
Value of the cursor parameter to get the previous page of the goods list, if the beginning of the list is not reached.
ProductData object
- id - integer always
Product identifier.
- type - string always
Product type: 'product', 'service', 'event', 'campaign', 'digital'
- name - string always
Product name.
- description - string optional
Detailed product description.
- icon - IconData optional
Parameters of configured icon or color mark to be displayed next to the product name.
- price - number optional
The product price in cents of the store's base currency whose code is returned by the getBaseCurrencyCode() method. This field is mutually exclusive with the multi_price field.
- multi_price - array of PriceData optional
A list of product price options. This field is mutually exclusive with the price field.
- price_model - string always if multi_price present
Tells if an order can contain several instances of the product with different price option: 'single' (only instance can be used), 'multi' (several product instances can be added)
- discount - number optional
The multiplier to be applied to the price of the product.
- allow_quantity - QuantityConfig optional
The presence of this object means that the buyer can specify the quantity of the product. The object contains the configuration for entering and displaying the quantity.
- rest_quantity - number optional
If there is an allow_quantity, the remainder of the product in stock can be specified here, if such a remainder is known
- allow_altprice - object optional
The presence of this object means that the buyer can specify his price. The object contains min and max fields with the minimum and maximum allowed price.
- attributes - array of AttributeData optional
A list of product attributes if it have any. A user must be presented with the interface which enables to select some value for every attribute.
- attributes_model - string always if attributes present
Tells if an order can contain several instances of the product with different set of attributes: 'single' (only instance can be used), 'multi' (several product instances can be added)
PriceData object
- id - string always
The identifier of the price option.
- name - string always
Price option name.
- icon - IconData optional
Parameters of configured icon or color mark to be displayed next to the price option.
- price - number always
The price of the product in cents of the store's base currency, the code of which is returned by the getBaseCurrencyCode() method.
- rest_quantity - number optional
In the case of allow_quantity in the product properties, the remainder of the product of this variant in stock can be specified here, if such a remainder is known.
QuantityConfig object
- unit - string always
Unit identifier: 'default','item','time','value','unit','pack','bottle','user' and so on. See the complete list in the unit chooser interface.
- role - string always
Possible values: 'quantity', 'factor' (if the price of the goods is indicated for a specific amount of stuff).
- can_extend - boolean optional
The flag shows if a buyer can proportionally extend the quantity of product/service in the cart. The flag is relevant only for the 'factor' role.
- step - number optional
The desired step of quantity change when the buyer presses the "increase"/"decrease" buttons. The default is 1.
- precision - integer optional
The number of decimal places after the decimal point in the quantity representation. The default value is 0, which means that the quantity is an integer.
- min - number always
The minimum quantity of product for the order item. If there are price options the limit applies to each included option separately.
- max - number always
The maximum quantity of product for the order item. If there are price options the limit applies to each included option separately.
AttributeData object
- id - integer always
The identifier of the attribute.
- name - string always
The name of the attribute to be displayed for the user.
- icon - IconData optional
Parameters of configured icon or color mark to be displayed next to the attribute name.
- values - array of AttributeValueData always
A list of possible values for the attribute.
AttributeValueData object
- id - integer always
The identifier of the attribute value.
- name - string always
The name of the attribute value to be displayed for the user.
- icon - IconData optional
Parameters of configured icon or color mark to be displayed next to the attribute name.
- default - boolean optional
A flag whose true value indicates if this attribute value must be initially preselected.
- disabled - boolean optional
A flag whose true value indicates that this attribute value is currently unavailable. So it can be skipped or shown as disabled.
IconData object
- type - string always
Type of the icon: 'color', 'emoji', 'image'.
- value - string optional
For the icon of 'color' type contains HTML color name or hex color code like "#RRGGBB". For 'emoji' type contains just string with the Unicode representation of some Emoji.
- url - string optional
For 'image' type contains full URL of the image.
- format - string optional
For 'image' type contains abbreviation of the image format: 'jpg', 'png' or 'gif'.
- width - string optional
For 'image' type contains width of the image in physical pixels.
- height - string optional
For 'image' type contains height of the image in physical pixels.
CartContent object
- items - array of CartItem always
An array of product data.
- totalAmount - number
The total amount of products cost, in cents of the store's base currency.
CartItem object
Is the instance of ProductData class with additional fields:
- _quantity - number optional
Quantity of cart product. For non-quantifiable items the field will be missing.
- _price - number always
The price of the product in cents of the store's base currency.
- _price_name - string optional
If there are price options for the product, here will be the name of the selected option.
- _attributes - object optional
If there are attributes for the product, here will be an object with attribute IDs in the keys and corresponding value IDs in the values.
- _amount - number always
The cost of this product, in cents of the store's base currency.
UnetApiError object
- error object always
Error description:
- code - string always
String with error code:
- access_denied - request authorization error, message will contain details
- general_failure - general failure, message will contain details
- invalid_docstate - document is already closed, synchronous 'preload...' method cannot be used
- invalid_id - ID format is invalid
- invalid_request - invalid API request, message will contain details
- not_found - element was not found
- request_denied - API server refused to fulfill the request, message and status will contain details
- request_error - request sending or reading error, status will be filled in case of HTTP error, catch - in case of runtime error
- request_failed - general request execution error which occurs for JSONP requests, details are unknown
- request_timeout - response timeout has expired
- is_temp - integer optional
A non-zero value indicates that the error may be temporary
- message - string optional
A more detailed description of the error
- status - integer optional
For errors generated by Ajax request response contains HTTP response status
- catch - any optional
The original error caught in the catch is saved here, if the error is not generated by this API
currencyInfo object
- id - string always
3-letter currency code
- name - string optional
Full currency name
- symbol - string optional
Currency symbol
- divisor - number always
Number of cents (pennies) in a unit of currency
- rate - number optional
Conversion rate. Shows the value of the currency in units of the store's base currency, that is, to get the amount in the currency the amount of the base currency will be divided by the specified rate. The default conversion rate is 1.
ShopInfo object
- url - string always
Full URL of the store web-page.
- currency - currencyInfo always
The default store currency and also the base currency of all product prices.
- alt_currencies - array of currencyInfo optional
Array of additional currencies with information about conversion rates. Allows viewing prices in alternative currencies.
- locale - string always
Store locale as "L2-C2", where L2 is the two-letter lower-case language code, C2 is the two-letter upper-case country code.
Utilities
- docReady
- htmlEncode
- colorSchemeChange
- numberSplit
- roundCurrencyUp
Look over the source code of the siteapi.js file to see the example of use the functions.
Example:
UnetAPI._util.docReady(function(){
unet_api.getCartItems().then(function(res){
var items = res.items;
var qty=0;
for (var i=0; i<items.length; i++){
var cart = items[i]._cart;
if (cart) qty+=(cart.quantity||1);
}
conosle.log(qty,'items in the shopping cart');
});
});