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. For write/edit operations to wishlist, use Javascript API . We also offer REST API.

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 the following fields:

NAMEDESCRIPTIONTYPE
countThe number of items returnedNumber
typeThe response type (success/error)String
messageRelevant message if an error occursString
itemsArray of wishlist items in JSON format.Array
idThe product id. A numeric id generated by Shopify for each product.String
titleThe title of the product.String
handleThe handle can be used to determine the URL of the product. A typical product URL would look like www.yourstore.com/products/handleString
variant_idIt is a numeric Id generated by Shopify and is unique across variants of all products.String
is_true_variantIf 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.Number
variant_countThe total number of available variants of the product.Number
variant_titleThe title of the product variantString
variant_priceThe price of the variant and consequently the price to be displayed to the user.String
variant_skuThe SKU assigned to the item/variantString
variant_out_of_stock0 if the variant is in stock, 1 if the variant is out of stockNumber
imageURL of the product image String
tagsTags assigned to the productString

Sample Request Code

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

//This jQuery based code fetches the contents of Express Wishlist (unregistered users)
var wishlistid=SWGetExpressWishlistId();    
$.ajax({
        url: "/a/wishlist?type=api&wishlistid="+wishlistid+"&version=1",
        dataType: "json",
	cache:false,
        success: function(data) {
	//your code for displaying the wishlist data.
	}

    });

//the above code adapted for customer wishlist (logged in users)
var customerid=SWGetCustomerWishlistId();
if(customerid!=0) //check if user is logged in
{	
$.ajax({
	url: "/a/wishlist?type=api&customerid="+customerid+"&version=1",
	dataType: "json",
	cache:false
	success: function(data) {
	//your code for displaying the wishlist data.
	}

    });
}	

Sample Response

A sample response is given below:

{
  "count": 3,
  "type": "success",
  "items": [
    {
      "id": "6372536837",
      "title": "Samsung Galaxy On7 Gold, 8 GB",
      "handle": "samsung-galaxy-on7-gold-8-gb",
      "variant_id": "21005590533",
      "is_true_variant": 0,
      "variant_count": 1,
      "variant_title": "Default Title",
      "variant_price": "120.00",
      "variant_out_of_stock":0,
      "tags": "",
      "image": "https:\\/\\/cdn.shopify.com\\/s\\/files\\/1\\/1528\\/3157\\/products\\/samsung-galaxy-on7-sm-g600f-400x400-imaecqkgzeuz9ebn_.jpg?v=1475649915"
    },
    {
      "id": "6372536709",
      "title": "Asus Zenfone 2 ZE551ML",
      "handle": "asus-zenfone-2-ze551ml",
      "variant_id": "21005590213",
      "is_true_variant": 0,
      "variant_count": 1,
      "variant_title": "Default Title",
      "variant_price": "200.00",
      "variant_out_of_stock":0,
      "tags": "",
      "image": "https:\\/\\/cdn.shopify.com\\/s\\/files\\/1\\/1528\\/3157\\/products\\/asus-ze551ml-ze551ml-6j333ww-400x400-imae6kggzusrx2cw_.jpg?v=1475649914"
    },
    {
      "id": "6372536965",
      "title": "Apple iPhone 5S",
      "handle": "apple-iphone-5s",
      "variant_id": "21005591941",
      "is_true_variant": 0,
      "variant_count": 1,
      "variant_title": "Default Title",
      "variant_price": "500.00",
      "variant_out_of_stock":0,
      "tags": "",
      "image": "https:\\/\\/cdn.shopify.com\\/s\\/files\\/1\\/1528\\/3157\\/products\\/apple-iphone-5s-400x400-imadpppcxjauphdg_.jpg?v=1475649916"
    }
  ],
  "message": ""
}

Exceptional Scenarios with API Response

  1. The variant-labeled fields (for e.g. variant_title, variant_price) return empty values. This happens when the variant was deleted from store after it being added to the wishlist, but the product still exists.

Leave a Reply

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