Smart Wishlist Public API

The Public API for Smart Wishlist is a primitive API, which can be used to fetch the Wishlist data. It can be used for multitude of purposes for e.g. populating the wishlist data in any type of display including modals, previews or any random page of the store. It can also be used to design a brand new custom wishlist page. When used along with Callback functions, it could be used to create an immersive wishlist experience.

NOTE: The Public API is a read-only API and supports only GET method. It doesn’t support ADD/REMOVE operations on Wishlist. We are separately launching the REST API, which shall support all native wishlist operations using POST/PUT methods.

Authentication

The public API doesn’t require any authentication. But it can only be accessed using your store’s domain and the Wishlist URL.

Request Path

The API can be requested using the same path as your wishlist page (/a/wishlist), by passing few additional parameters. In case your wishlist is accessible at a path other than /a/wishlist, you need to replace this with the altered wishlist path.

1. Path for accessing wishlist data of registered users:

/a/wishlist?type=api&customerid=123456789&version=1

2. Path for accessing wishlist data of non-registered users:

/a/wishlist?type=api&wishlistid=123456789&version=1

Request Parameters

1. type: It’s mandatory and its value must be api in order for the API to work.

2. customerid: It is a unique numeric id generated by Shopify for each registered user.

NOTE: You can fetch the customerid using a built in Javascript function SWGetCustomerWishlistId(). If the user is not logged in, it returns 0. This function can also be used to check if the user is logged in or not.

3. wishlistid: It is a unique alphanumeric string generated by the app for each non-registered user.

NOTE: You can fetch the wishlistid using a built in Javascript function SWGetExpressWishlistId().

Important: You must provide either of customerid or wishlistid in the path, depending on the type of user, while making an API request. In case both is present in the path or none is present, the response could be unpredictable.

4. version As of now its only acceptable value is 1. Its usage would ensure that your implementation won’t break even if we introduce changes in future.

Note: We have noticed that when accessing the API via Javascript, Shopify sometimes caches the XHR requests. Therefore, It is recommended that all API requests must be cache-invalidated. In jQuery, this can be achieved by setting cache:false (see sample code below). In vanilla Javascript, this can be achieved by simply appending &_=some_random_string to the request URL.

Response

The response in both the cases is in the JSON format. It contains a minimum of following fields:

1. count: The number of items returned

2. type: The response type (success/error)

3. message: Relevant message if an error occurs

4. items: Array of wishlist items in JSON format.

5. id: A numeric id generated by Shopify for each product.

6. title: The title of the product.

7. handle: The handle can be used to determine the URL of the product. A typical product URL would look like www.yourstore.com/products/handle

8. variant_id: It is a numeric Id generated by Shopify and is unique across variants of all products.

9. is_true_variant: If set to 1, it means that the user has added this particular variant to the wishlist. If set to 0, it means that user may not have added the selected variant to the wishlist and in such cases the chosen variant need to be confirmed by the user before adding the item to cart.

10. variant_count: The total number of available variants of the product.

11. variant_title: The title of the product variant

12. variant_price: The price of the variant and consequently the price to be displayed to the user.

13. image: The product image to be displayed

Sample Request Code

The following code uses jQuery’s ajax function to fetch the wishlist data

Sample Response

A typical sample response is given below:

Leave a Reply

Your email address will not be published. Required fields are marked *