Today i will show you how you get the top voted products from our productlayer API.
- API-KEY – if you don’t have one go to developer.productlayer.com and signup for a developer account and create a new app
Step by step guide:
- We need to know what information we are looking for
- return type: product
- amount: 5
- sorted by: voting score
- request type: GET
- 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”.
- Now we can search for a “GET” request but there is no specific request to get the top voted products.
- There is an endpoint for searching products and this endpoint also supports an order_by parameter
- You can test the response of the endpoint by using the web client at developer.productlayer.com
- 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).
- page: 0
- If we now execute the request we will get a JSON array with 5 products sorted by the voting score.