ProductsClearAll Endpoint

Overview

If you ever have the need to delete all of the products from your store catalog, this is the right endpoint of the REST API to use.  Please note that this endpoint requires that you enable a higher level of permissions in the store administration.  Go to the API page of the Admin menu to enable it. 

Requirements

The following pre-requisites will be necessary to accomplish the goals of this article:

  • General understanding of REST and API’s
  • Understanding of C# and/or JavaScript
  • Visual Studio 2012 or newer

Getting Started

If you haven’t done so already, you’ll need to login on your Hotcakes website as an administrator or superuser (host user).  This endpoint requires that you enable a higher level of permissions in the API.  This is because the act of deleting or destroying all products is such a dangerous thing to do.  You cannot restore the products once they are deleted. 

Once you are in the store administration, go to the API page in the Admin menu.  Clicking the button to allow “clear all” operations will enable all of the “clear all” operations for 60 minutes.

Allow Clear All Operations in the API

ProductsClearAll

This REST API endpoint allows you to permanently delete all products from your store catalog. 

Example URL

This is what the REST endpoint will look like if you are calling it using JavaScript.  See our REST API URL documentation for more information.

http://yourdomain.com/DesktopModules/Hotcakes/API/rest/v1/products?key=[YOURKEY]&howmany=[HOWMANY]

HTTP Method

DELETE

Parameters

Parameter Description
howmany The number of products you want to delete at once. Supply the total count except if the catalog deletion will take longer than an HttpRequest allows. This allows you to delete all in increments, instead of all at once (which you can still do as well, as shown in the examples below).

Return Values   

If successful, this endpoint will return a populated ClearProductsData object in JSON format.  Otherwise, you should have one or more errors returned.  

Example Code

The following code will allow you to successfully call this endpoint, provided that you have enabled it.

Project References

  • Hotcakes.CommerceDTO

Import Namespaces

  • Hotcakes.CommerceDTO.v1
  • Hotcakes.CommerceDTO.v1.Catalog
  • Hotcakes.CommerceDTO.v1.Client

 

string url = "http://YOURDOMAIN.COM";
string key = "YOUR-API-KEY";

Api proxy = new Api(url, key);

// get a count of the total number of products in the store
var productCount = (int)proxy.ProductsCountOfAll().Content;

// call the API to permanently delete all products in the store
ApiResponse<ClearProductsData> response = proxy.ProductsClearAll(productCount);
// your domain name
var url = "http://YOURDOMAIN.COM"; 
// the path where the API is
var apiPath = "/DesktopModules/Hotcakes/API/rest/v1/";  
// endpoint as shown in the documentation
var endPoint = "products";  
// get this from the store admin
var apiKey = "YOUR-API-KEY";

$(document).ready(function() {

    // call the API to get a count of all products in the store
    $.ajax({
        dataType: "json",
        url: url + apiPath + endPoint + "?key=" + apiKey + "&countonly=1",
        type: 'GET',
        success: function (data) {
            // call the clear all method using the total count
            deleteAllProducts(data.Content);
        },
        error: function(jqXHR, textStatus) {
            // do something
        }
    });

});

function deleteAllProducts(howMany) {

    // call the API to permanently delete all products in the store
    $.ajax({
        dataType: "json",
        url: url + apiPath + endPoint + "?key=" + apiKey + "&howmany=" + howMany,
        type: 'DELETE',
        success: function (data) {
            // do something
        },
        error: function (jqXHR, textStatus) {
            // do something else
        }
    });
            
}
{
   "Errors":[

   ],
   "Content":{
      "ProductsCleared":7,
      "ProductsRemaining":0
   }
}
Have more questions? Submit a request

Need More Help?

Do you need more assistance with this article? Please review your support options.