Getting the product info for a content or in general.
support, ws.webtv, api, store, product
GET vars specific to this request:
Var | Value | Description |
go | store | The API section |
do | get_product | The API action |
iq | User ID | The User ID |
Resulting Request URL:
The resulting request URL would be similar to this (don't forget to append the required info: key, timestamp, salt and signature):
https://....../api.php?go=store&do=get_product&iq={user_id}&{required information}
The following POST vars are required.
Var | Value | Description |
type | (string) Product Type | Possible values: "clip", "channel", "other". Special cases intended for getting related products only: "site", "service", "donation". |
cpID | (int) Content or Product ID | ID of the content or product: - If "type" is "clip" or "channel": Provide Clip or Channel ID. - If "type" is "other": Provide the product ID. - If "type" is of a special case: Provide -1. |
The following POST var is optional.
Var | Value | Description |
get_related | (int) 0|1 | Whether to get related products. Possible values: 1 (Yes, default), 0 (No) |
If the request was successful, you'll receive a response containing:
• overview: An array with the overview information. The overview info is the one you will normally display to the User when visiting the page of a product then, at the bottom (or any other place you consider), you should display the list of associated products (which are the ones that can be added to the cart). Note that for the special cases of "type" the overview will be empty and the response will only contain related products.
The overview info will inlude:
- title: (string) The main title for the content or product.
- description: (string) The main description for the content or product.
- description_seo: (string) A plain text version of the description.
- tags: (string) Related tags (if any).
- img_poster, img_social, img_thumbnail: (string) The image (in several sizes) for the content or product.
- max_price: (decimal) The maximum price of the associated products (in case there is more than one).
- max_price_formatted: (string) The previous value, formatted.
- min_price: (decimal) The minimum price of the associated products (in case there is more than one).
- min_price_formatted: (string) The previous value, formatted.
• associated_products: An array with the list of products directly associated with the request (Clips and Channels mayt have more than one associated product).
• related_products: An array with the list of related products.
The list of associated or related products will include the following info:
- id: (int) The product ID. This is the ID that you will use for adding the product from the cart.
- id_clip: (int) In case this is a Clip product, this will be Clip ID (number > 0).
- id_channel: (int) In case this is a Channel product, this will be Channel ID (number > 0).
- id_type: (int) ID of the product type.
- ctype: (int) Content type of the product (-1:Other, 0:Site, 1:Channel, 2:Clip, 3:Membersip).
- sku: (string) SKU of the product.
- price: (decimal) The unit price of the product.
- price_formatted: (string) The previous value, formatted.
- title: (string) The product title.
- description: (string) The product description.
- img_thumbnail, img_social, img_poster: (string) The product image, in several sizes.
- quantity_options: (string) Comma separated values. Some products like "credits" or "donations" have several quantity options and a unit price equal to 1.
Example:
{ "overview": { "description": "Add credit to your account and use it any time to purchase WebTV content access.<br> Purchasing with your credit balance is very fast and easy. If you have enough credit to purchase an item you will be able to use the Quick Purchase option that does not require going through the check out process. <br>NOTE: Credits can not be used to pay subscription renewals when recurring payments (automatic payments) are active for a subscription.", "description_seo": "Add credit to your account and use it any time to purchase WebTV content access. Purchasing with your credit balance is very fast and easy. If you have enough credit to purchase an item you will be able to use the Quick Purchase option that does not require going through the check out process. NOTE: Credits can not be used to pay subscription renewals when recurring payments (automatic payments) are active for a subscription.", "img_poster": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_credit_poster.jpg", "img_social": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_credit_social.jpg", "img_thumbnail": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_credit_thumb.jpg", "max_price": 30, "max_price_formatted": "30.00\u20ac", "min_price": 5, "min_price_formatted": "5.00\u20ac", "tags": "", "title": "Credit Recharge" }, "associated_products": { "1": { "id": "1", "id_clip": null, "id_channel": null, "id_type": "1", "ctype": "0", "sku": "CREDIT", "price": "1.00", "title": "Credit Recharge", "description": "Add credit to your account and use it any time to purchase WebTV content access.<br> Purchasing with your credit balance is very fast and easy. If you have enough credit to purchase an item you will be able to use the Quick Purchase option that does not require going through the check out process. <br>NOTE: Credits can not be used to pay subscription renewals when recurring payments (automatic payments) are active for a subscription.", "img_thumbnail": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_credit_thumb.jpg", "img_social": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_credit_social.jpg", "img_poster": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_credit_poster.jpg", "quantity_options": "5,10,15,20,25,30", "price_formatted": "1.00\u20ac" } }, "related_products": { "2": { "id": "2", "id_clip": null, "id_channel": null, "id_type": "3", "ctype": "0", "sku": "SITEACCPER", "price": "9.99", "title": "WebTV Access Pass (during 1 day)", "description": "Full WebTV content access pass during 1 day", "img_thumbnail": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_site_pass_period_thumb.jpg", "img_social": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_site_pass_period_social.jpg", "img_poster": "http:\/\/www.mywebtvdomain.com\/public\/common\/images\/_default_store_product_site_pass_period_poster.jpg", "quantity_options": "1", "price_formatted": "9.99\u20ac" } } }
If the request failed (for example, if no signature was provided in the request), you'll receive a response like the following:
{ "error" : "REQUEST_ERROR", "error_long" : "Missing signature" }
Possible Error Messages
Besides the general errors, this request can return the following errors:
• REQUEST_ERROR | Invalid User ID:
User ID is not numeric or lower than 1.
• REQUEST_ERROR | Invalid product type:
The "type" was not specified or it is not among the allowed ones.
• REQUEST_ERROR | Invalid cotnent or product ID:
The "cpID" was not specified or it is not valid.
• ERROR_PRODUCT_NOT_FOUND | Product not found:
The product could not be found.
Preparing GET and POST data.
// The GET vars $GET_VARS = array( "go" => "store", "do" => "get_product", "iq" => "2" ); // The POST vars (several cases...) // ...case of Clip with ID=68 $POST_VARS = array( "type" => "clip", "cpID" => 68, "get_related" => 1 ); // ...case of product with con ID=1 ("Credit") $POST_VARS = array( "type" => "other", "cpID" => 1, "get_related" => 1 ); // ...special case for getting products related with the type "site" (Ctrédit, Global Access Passes and Memberships) $POST_VARS = array( "type" => "site", "cpID" => -1, "get_related" => 1 ); // ...special case for getting products related with the type "service" (Services) $POST_VARS = array( "type" => "service", "cpID" => -1, "get_related" => 1 ); // ...special case for getting products related with the type "donation" (Donations) $POST_VARS = array( "type" => "service", "cpID" => -1, "get_related" => 1 );
Generating the salt, timestamp, signature and sending the request
*** The following code block is common to all signed requests ***
// Collect the API Base URL and Credential info $API_URL = "https://www.mywebtvdomain.tv/api.php"; $API_KEY_ID = "1b323a1cb879fd4e66530fbad07a32ee"; $API_SHARED_SECRET = "MWIzMjNhMWNiODc5ZmQ0ZTY2NTMwZmJhZDA3YTMyZWViOTQ3MDJiOGM2ZTU2NjE3"; // keep this safe!!! // Generating salt and timestamp $salt = md5(mt_rand()); $timestamp = time(); $signature = base64_encode(hash_hmac('sha256', $salt.$timestamp, $API_SHARED_SECRET, true)); // Generating the validation signature // - Default method: using base64_encode(hash_hmac(...)) $signature = base64_encode(hash_hmac('sha256', $salt.$timestamp, $API_SHARED_SECRET, true)); // comment this line if using the next method // - Simplified method - available since v60: using md5(). // This method requires the variable $API_SIGNATURE_GENERATION_MODE = 1; in the config/Config.inc.php file. // $signature = md5($salt."-".$timestamp."-".$API_SHARED_SECRET); // you must "uncomment" this line when using the simplified method // Append the timestamp, salt, key and signature to the GET vars $GET_VARS["timestamp"] = $timestamp; // UTC timestamp $GET_VARS["salt"] = $salt; $GET_VARS["key"] = $API_KEY_ID ; // The API Key ID: This is public and is used by the API to identify the application; $GET_VARS["signature"] = $signature; // Create the request URL. Please note that if you do not use PHP buit in function // to create the HTTP query then don't forget to URL encode the values $REQUEST_URL = $API_URL."?".http_build_query($GET_VARS); // The previous will build an URL like .../api.php?go=api_subject&do=api_action&etc... // Create a new cURL resource and set the appropriate options $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $REQUEST_URL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $POST_VARS); // If your PHP host does not have a valid SSL certificate, you will need to turn off SSL // Certificate Verification. This is dangerous (!), and should only be done temporarily // until a valid certificate has been installed curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Turns off verification of the SSL certificate. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turns off verification of the SSL certificate. // Sending the request to the API $response = curl_exec($ch); // Processing the response if (!$response) { echo 'API call failed'; } else { print_r(json_decode($response,true)); }