HowTo: Get the highest voted products via API

Today i will show you how you get the top voted products from our productlayer API.

Prerequisites:

Step by step guide:

  1. We need to know what information we are looking for
    • return type: product
    • amount: 5
    • sorted by: voting score
    • request type: GET
  2. Now we need to identify the right endpoint for getting products as return type.
    • The best way to do that is to open the API-Documentation and choose the service which fit’s best. For our task it’s the “Product Service”.
  3. Now we can search for a “GET” request but there is no specific request to get the top voted products.
  4. There is an endpoint for searching products and this endpoint also supports an order_by parameter
      • /products?query={query}&gtin={gtin}&name={name}&language={language}&page={page}&records_per_page={records_per_page}&order_by={order_by}
      • You can test the response of the endpoint by using the web client at developer.productlayer.com

    Screen Shot 2014-10-22 at 14.00.13

  5. Now we need to identify the right parameters for the request:
    • page: 0
      • The page you want to view starting with 0. If no page has been provided, the first page will be shown.
    • records_per_page: 5
      • How many products should be displayed per page. The default value is 50 records per page.
    • order_by: pl-vote-score_desc
      • The order_by keyword is used to sort the result-set by one or more columns. The order by parameters are seperated by a semicolon. Also you need to provide a prefix asc for ascending or desc for descending order.
      • e.g.: pl-prod-name_asc (Product names ascending)
      • You can sort by all key’s provided by the requested entity (in our case product).
  6. If we now execute the request we will get a JSON array with 5 products sorted by the voting score.

Submit a Comment

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