Back to Website
Product Documentation Developers Integration Hub Customer API - Fetch a Category, it's Products and Filters

Customer API - Fetch a Category, It's Products and Filters

In this guide, we're going to take you through how you can fetch a category, its products and filters, through the Kodaris API.

Video overview:

https://www.youtube.com/watch?v=MXOegUadWDQ
  1. Sign In
    • Note: Skip this step if you want to get data as a guest user.
    • In order to get customer specific information, you will want to sign in to an account through the API.
    • Call the endpoint: POST / api/user/customer/apiKeyLogin
      • Headers
        • Accept - application/json
        • Content-Type - application/json
      • Body
        • apiKey - the api key of your api user.
      • Response
        • A response will be returned indicating whether the login was successful or not. The response will also contain your userSessionApiKey that you will need to use on future requests to get responses back as a authenticated user.
  2. Fetch an Auth Token
    • Note: Skip this step if you want to get data as a guest user.
    • You'll need an authorization token for any API requests you make to the Kodaris API.
    • Fetch one using the endpoint: GET / api/user/customer/authToken
      • Headers
        • Accept - application/json
        • Content-Type - application/json
        • userSessionApiKey - the userSessionApiKey from the /apiKeyLogin endpoint response
      • Response
        • The returned response will contain your auth token that you will need to use on future requests.
  3. Fetch a Category, Its Products and Filters
    • Now you can fetch a category, its products and filters, as an authenticated user.
    • Send an API request to endpoint: GET api/user/category/{categoryCode}
      • Headers
        • Accept - application/json
        • Content-Type - application/json
        • userSessionApiKey - the userSessionApiKey from the /apiKeyLogin endpoint response
          • (Note: skip this header if you want to get data as a guest user.)
        • X-CSRF-TOKEN - the auth token from the /authToken endpoint response
          • (Note: skip this header if you want to get data as a guest user.)
      • Query Params
        • includeFilters - true
          • Sending this query parameter returns the filters along with the products. If you don't want filters returned, simply skip this.
        • page - 1
          • Sending this query parameter specifies the which page of results you would like returned, e.g. sending 1 will return you the first results page.
        • facets - fg_brand|fg_brand_usg
          • If you would like to filter for certain products in the category, for example USG brand products, just send in the facet code like shown above. These filters and facet codes are returned in the response if you send in the query parameter: includeFilters - true.
      • Response
        • The returned response will include the category products and filters (if you requested them).

Example

// Login to our account
var loginRes = kd.http.fetch({
  method: 'POST',
  url: 'https://content.kodaris.com/api/user/customer/apiKeyLogin',
  version: 2,
  body: {
    apiKey: 'xxxx'
  },
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
});

// keep our session token for future requests
var userSessionApiKey = loginRes.body.data.userSessionApiKey;

// get CRSF token for requests
var tokenRes = kd.http.fetch({
  method: 'GET',
  url: 'https://content.kodaris.com/api/user/customer/authToken',
  version: 2,
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'userSessionApiKey': userSessionApiKey
  }
});

// keep our token for future requests
var token = tokenRes.body.data;

// get customer side category
var categoryRes = kd.http.fetch({
  method: 'GET',
  url: 'https://content.kodaris.com/api/user/category/ceilings',
  version: 2,
  queryParams: {
    "includeFilters": true,
    "facets": 'fg_brand|fg_brand_usg',
    "page": 1
  },
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'userSessionApiKey': userSessionApiKey,
    'X-CSRF-TOKEN': token
  }
});

kd.log('categoryRes', categoryRes);

-> response ->
{
  "status" : 200,
  "errors" : null,
  "body" : {
    "code" : 200,
    "success" : true,
    "errors" : { },
    "messages" : { },
    "data" : {
      "size" : 24,
      "number" : 2,
      "totalElements" : 134,
      "isLast" : false,
      "totalPages" : 6,
      "isFirst" : false,
      "hasPrevious" : true,
      "hasNext" : true,
      "numberOfElements" : 134,
      "offset" : 2,
      "content" : {
        "0" : {
          "productID" : 9535,
          "code" : "ZAMAC02814",
          "seoCode" : "ZAMAC02814",
          "name" : "1 in x 1/2 in x 3/4 in x 10 ft USG Suspension System U Molding - US12",
          "description" : " All of the tools you need to install your suspension system quickly and easily. Donn® Brand Acoustical Suspension System Accessories; provides everything you need to install your suspension system. With everything from galvanized hanger wire to stabilizer bars to cross tee hole punches, your ceiling project is sure to go quickly and smoothly.     Details        Color: White        Includes        50 pieces per carton    500 linear feet per carton    ",
          "unitStock" : null,
          "smallImage" : "https://s3.amazonaws.com/commerce.kodaris.com/product/SM-USG_U_Channel.jpg",
          "mediumImage" : "https://s3.amazonaws.com/commerce.kodaris.com/product/MD-USG_U_Channel.jpg",
          "largeImage" : "https://s3.amazonaws.com/commerce.kodaris.com/product/LG-USG_U_Channel.jpg",
          "unitSell" : null,
          "unitPrice" : 290.1499938964844,
          "unitPriceConversionFactor" : null,
          "unitContainer" : null,
          "priceCalculationType" : null,
          "url" : "https://content.kodaris.com/product/ceilings/ZAMAC02814",
          "manufacturerCode" : null,
          "manufacturerProductCode" : null,
          "displayFootageCalculator" : false,
          "directShipped" : false,
          "productType" : null
        },
... omitted for brevity
      },
      "filters" : {
        "0" : {
          "type" : "link",
          "name" : "Categories",
          "attributes" : {
            "0" : {
              "code" : "ceiling_grid_trim",
              "name" : "Ceiling Grid & Trim",
              "count" : 80,
              "url" : "/category/ceilings/ceiling_grid_trim",
              "categoryOrder" : 0,
              "mediumImage" : null
            },
            "1" : {
              "code" : "ceiling_acoustical",
              "name" : "Acoustical Tile",
              "count" : 28,
              "url" : "/category/ceilings/Acoustical Tiles",
              "categoryOrder" : 0,
              "mediumImage" : null
            },
            "2" : {
              "code" : "ceiling_tile_panels",
              "name" : "Ceiling Tile & Panels",
              "count" : 26,
              "url" : "/category/ceilings/ceiling_tile_panels",
              "categoryOrder" : 0,
              "mediumImage" : null
            }
          }
        },
        "1" : {
          "code" : "inStockAtWarehouse",
          "showCounts" : false,
          "name" : "Usually Ships Next Day",
          "type" : "checkbox",
          "attributes" : {
            "0" : {
              "name" : "Yes",
              "active" : false,
              "value" : "EV"
            }
          }
        },
        "2" : {
          "code" : "facets",
          "name" : "Acoustical Edge",
          "value" : "fg_Edge",
          "attributes" : {
            "0" : {
              "name" : "Fineline",
              "count" : 11,
              "active" : false,
              "value" : "fg_Edge|fg_Edge_fineline",
              "categoryOrder" : 0
            },
            "1" : {
              "name" : "Fineline Bevel",
              "count" : 8,
              "active" : false,
              "value" : "fg_Edge|fg_Edge_finelineBevel",
              "categoryOrder" : 0
            },
            "2" : {
              "name" : "Shadowline",
              "count" : 10,
              "active" : false,
              "value" : "fg_Edge|fg_Edge_shadowline",
              "categoryOrder" : 0
            },
            "3" : {
              "name" : "Shadowline Bevel",
              "count" : 2,
              "active" : false,
              "value" : "fg_Edge|fg_Edge_shadowlineBevel",
              "categoryOrder" : 0
            },
            "4" : {
              "name" : "Shadowline Tapered",
              "count" : 9,
              "active" : false,
              "value" : "fg_Edge|fg_Edge_shadowlineTapered",
              "categoryOrder" : 0
            },
            "5" : {
              "name" : "Square Edge",
              "count" : 12,
              "active" : false,
              "value" : "fg_Edge|fg_Edge_squareEdge",
              "categoryOrder" : 0
            }
          },
          "productDisplay" : false,
          "valuesOrderBy" : "nameAsNumber"
        },
        "5" : {
          "code" : "facets",
          "name" : "Product Brands",
          "value" : "fg_brand",
          "attributes" : {
            "0" : {
              "name" : "Cemco",
              "count" : 1,
              "active" : false,
              "value" : "fg_brand|fg_brand_cemco",
              "categoryOrder" : 0
            },
            "1" : {
              "name" : "Rockfon",
              "count" : 42,
              "active" : false,
              "value" : "fg_brand|fg_brand_rockfon",
              "categoryOrder" : 0
            },
            "2" : {
              "name" : "CertainTeed",
              "count" : 44,
              "active" : false,
              "value" : "fg_brand|fg_brand_certainTeed",
              "categoryOrder" : 0
            },
            "3" : {
              "name" : "USG",
              "count" : 134,
              "active" : true,
              "value" : "fg_brand|fg_brand_usg",
              "categoryOrder" : 0
            }
          },
          "productDisplay" : true,
          "valuesOrderBy" : "categoryOrder"
        }
... omitted for brevity
      },
      "sort" : "",
      "searchString" : ""
    }
  }
}

In this article