ListProducts

SmithCart > Integration > REST Endpoints
Usage
Lists all products
Basic URI
/products.json?top={top}&skip={skip}&orderby={orderby}
Parameters
int top               The maximum number of rows to return
long skip            The start row index
string orderby    A sort expression
HTTP Example
https://domain.com/DesktopModules/Smith.BuyNow/Services/v1/Checkout.svc/products.json?top=10&skip=0&orderby=-order_date
AUTH
Bearer JWT
 
C# Code
 
JavaScript Code
<script>
   (function ($) {
       var CLIENT_ID = "4SnPA6lqpY76ODEr",
           SERVICE_URI = "https://domain.com/DesktopModules/Smith.BuyNow/Services/v1/",
           DATA_LIMIT = "30",
           SKIP = "0",
           ORDER_BY = "-order_date";

       function listProducts (endPoint, clientID, top, skip, orderBy) {
           var jwt = sessionStorage.getItem("jwt");
           if (!jwt) {
               var uri = endPoint + "Authorize.ashx?"
                   + "response_type=token"
                   + "&client_id=" + clientID
                   + "&redirect_uri=" + encodeURIComponent(window.location)
                   + "&scope=" + encodeURIComponent("products create edit delete");
               window.location = uri;
               return;
           }

           $.ajax({
               type: "GET",
               url: endPoint + "/Checkout.svc/products.json?top="
                    + top + "&skip=" + skip + "&orderby=" + orderBy,
               headers: { "Authorization": "Bearer " + jwt },
               contentType: "application/json; charset=utf-8",
               dataType: "json"
           }).fail(function (jqXHR, textStatus) {
               console.log("SmithCart API: " + textStatus);
           });
       }

       $(function () {
           var params = {},
               queryString = location.hash.substring(1),
               regex = /([^&=]+)=([^&]*)/g,
               m;

           while (m = regex.exec(queryString)) {
               params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
           }
           if (params["access_token"]) {
               sessionStorage.setItem("jwt", params["access_token"]);
           }

           listProducts (SERVICE_URI, CLIENT_ID, DATA_LIMIT, SKIP, ORDER_BY);
       });
   })(jQuery);
</script>
 
 
 
Response
[
    {
        "id": 2,
        "category": "Test Category",
        "manufacturer": "Test Manufacturer",
        "model_no": "SCTest2",
        "model_name": "Smith Test Product #2",
        "unit_cost": 10.00,
        "qty_onhand": 999,
        "summary": null,
        "description": null,
        "ship_cost": 2.00,
        "width": -1,
        "height": -1,
        "length": -1,
        "sale_price": 6.99,
        "min_qty": -1,
        "max_qty": -1,
        "recurring": 1,
        "created_date": "\/Date(1422050765742-0800)\/",
        "updated_date": "\/Date(1422050765742-0800)\/"
    },
    {
        "id": 1,
        "category": "Test Category",
        "manufacturer": "Test Manufacturer",
        "model_no": "SCTest1",
        "model_name": "Smith Test Product #1",
        "unit_cost": 15.00,
        "qty_onhand": 50,
        "summary": "Test summary",
        "description": "Test description",
        "ship_cost": 0.00,
        "width": -1,
        "height": -1,
        "length": -1,
        "sale_price": 12.50,
        "min_qty": -1,
        "max_qty": -1,
        "recurring": 0,
        "created_date": "\/Date(1422050753657-0800)\/",
        "updated_date": "\/Date(1422050753657-0800)\/"
    }
]