Welcome to our support center
Developers
Fetching Products
Prerequistes
This section expects prior knowledge and understanding from the sections indicated below. Please note that these areas are essential to obtaining a successful response and notifying your server upon completion.
- API Overview
- API Key and Merchant ID
- Live Payment Notification (LPN)
- Product APIs
Overview
The FetchProducts API is very useful for updating the calling server with a full or filter list of products. Each search has the option of refining the results through the use of the search_by (column name) and keyword (row value).
Parameters
The fetchProduct API takes the following parameters:
- merchant_id - The merchant ID that can be found within the merchant console. (Compulsory)
- api_key - The API Key associated with the merchant ID. This is used to authorise and identify the caller of the request. (Compulsory)
- search_by - The field you want to search by, this can such things as the product_id, prod_description or prod_name. A full list of these can be found in the Creating Products.
- keyword - The value of the field that is needing to be searched. Such examples of this can be 'Awesome Product' for the prod_name field or alternatively '1958DC65E77902' for product_id.
Example Request
If you omit the 'search_by' and 'keyword' parameters, the API will return every product in your account. The following API call is an example of this:
To search for a product with a known product_id, append the following parameters to the API call:
Responses
If the API call was successful, it will return the product data in JSON format.
{ "response_code":200, "message":"OK", "data":{ "0":{ "prod_accepted_url":"", "prod_attribute":"", "prod_button_code":"18", "prod_button_type":"input", "prod_category":"", "prod_declined_url":"", "prod_description":"Magazine", "prod_detail":"", "prod_feature":"", "prod_image":"", "prod_keyword":"", "prod_last_updated":"1405657391", "prod_mcid":"123E59334B8338", "prod_minimum_purchase":"1", "prod_name":"Magazine", "prod_rrp":"15", "prod_sale_price":"15", "prod_sale_price_aud":"13.95", "prod_sale_price_cad":"12.77", "prod_sale_price_cny":"87.88", "prod_sale_price_eur":"9.48", "prod_sale_price_gbp":"8.09", "prod_sale_price_hkd":"97", "prod_sale_price_jpy":"1209.75", "prod_sale_price_krw":"16324.95", "prod_sale_price_nzd":"5.00", "prod_sale_price_sgd":"15.83", "prod_sale_price_usd":"13.04", "prod_sale_price_zar":"114.78", "prod_shipping":"", "prod_status":"active", "prod_stock":"20", "prod_stock_enabled":"yes", "product_id":"7975FAA0E527F" } } }
Test Code
Below is an example code that will work against a test section of the server. Although this is intended to simulate server behaviour, characteristics and responses are not always the same.
Please note that no transactions will be sent online and the server will not store any information from these requests. For more information on this, please see Testing Without An Account
<?php /** * Function used to make POST requests to the server using SSL. * * @param type $url The API URL that we want to send the request to. * @param type $data POST data that will be sent to the server. * @return false Returns the HTML response as a String. If an error has occured null will be returned. */ function post_to_url($url, $data) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $html = curl_exec($ch); if (curl_errno($ch) !== 0) { curl_close($ch); return false; } curl_close($ch); return $html; } //The POST data that will be sent to the server. $postData = array( 'api_key' => 'ida8463534kawhdi347d39h078dt3383', 'merchant_id' => '123E59334B8338', 'search_by' => 'prod_name', 'keyword' => 'Magazine', ); //Make the request to the server $result = post_to_url("https://merchant.cybercompay.com/examples/fetchProducts.php", $postData); //If we have encountered an error display something back to the customer. if ($result === false) { echo 'We have encountered an error!'; exit; } //Print the results. print_r(json_decode($result));