GetProductByID

SmithCart > Integration > REST Endpoints
Usage
Retrieve a product by ID
Basic URI
/products/{pid}.json
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/1.json
AUTH
Bearer JWT
 
C# Code
 
JavaScript Code
<script>
   (function ($) {
       var CLIENT_ID = "4SnPA6lqpY76ODEr",
           SERVICE_URI = "https://domain.com/DesktopModules/Smith.BuyNow/Services/v1/",
           PRODUCT_ID = "1";

       function getProduct (endPoint, clientID, pID) {
           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/" + pID + ".json",
               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"]);
           }

           getProduct (SERVICE_URI, CLIENT_ID, PRODUCT_ID);
       });
   })(jQuery);
</script>
 
 
 
Response
[
    "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)\/"
]