Difference between revisions of "API:Product:get weight"
(New page: Retrieves the weight, in ounces, of an item or the sum total of the weight of a collection of items. ===Calling=== <code php>$api->user->get_username($item_sku);</code> <code php>$api->us...) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | Retrieves the weight, in ounces, of an item or the sum total of the weight of a collection of items. | + | Retrieves the weight, in ounces, of an item or the sum total of the weight of a collection of items. '''This method is only available to API applications that have order placement privileges'''. |
+ | |||
+ | It is recommended that you cache the values returned from this function locally so as to limit the number of server API calls that your application makes. | ||
===Calling=== | ===Calling=== | ||
− | <code php>$api-> | + | <code php>$api->product->get_weight($item_sku);</code> |
− | <code php>$api-> | + | <code php>$api->product->get_weight(array($item_sku_1, $item_sku_2, ..., $item_sku_n));</code> |
===Parameters=== | ===Parameters=== | ||
− | '''<nowiki>$</nowiki>item_sku''' - The SKU of an item. May also be a list of items in which case the sum weight total of the items is returned. | + | '''<nowiki>$</nowiki>item_sku''' - The SKU of an item. May also be a list of items in which case the sum weight total of the items is returned. ([[API:Product_List|List of Products]]) |
===Returns=== | ===Returns=== | ||
Line 19: | Line 21: | ||
===Example=== | ===Example=== | ||
− | <code php | + | <code php>require_once 'AoPSAPI.php'; |
$api = new AoPSAPI('<api_key>', '<secret_key>'); | $api = new AoPSAPI('<api_key>', '<secret_key>'); | ||
Line 28: | Line 30: | ||
$result = $api->product->get_weight(array('intro:algebra', 'intro:algebra:solutions')); | $result = $api->product->get_weight(array('intro:algebra', 'intro:algebra:solutions')); | ||
− | echo 'The combined weight of Introduction to Algebra and its solutions manual is ' . $result . ' ounces.<br />'; | + | echo 'The combined weight of Introduction to Algebra and its solutions manual is ' . |
+ | $result . ' ounces.<br />'; | ||
} | } | ||
catch (AoPSAPI_Exception $ex) | catch (AoPSAPI_Exception $ex) | ||
{ | { | ||
− | echo $ex->getMessage() . "<br /> | + | echo $ex->getMessage() . "<br />"; |
}</code> | }</code> | ||
Line 38: | Line 41: | ||
The weight of Introduction to Algebra is 53 ounces. | The weight of Introduction to Algebra is 53 ounces. | ||
The combined weight of Introduction to Algebra and its solutions manual is 79 ounces. | The combined weight of Introduction to Algebra and its solutions manual is 79 ounces. | ||
+ | |||
+ | ===See Also=== | ||
+ | [[API:Product_List|List of Products]] |
Latest revision as of 16:58, 28 May 2009
Retrieves the weight, in ounces, of an item or the sum total of the weight of a collection of items. This method is only available to API applications that have order placement privileges.
It is recommended that you cache the values returned from this function locally so as to limit the number of server API calls that your application makes.
Calling
$api->product->get_weight($item_sku);
$api->product->get_weight(array($item_sku_1, $item_sku_2, ..., $item_sku_n));
Parameters
$item_sku - The SKU of an item. May also be a list of items in which case the sum weight total of the items is returned. (List of Products)
Returns
The weight, in ounces, of the item or collection of items.
Exceptions
AoPSAPI_Exception::MISSING_PARAMETER - Missing item sku or list of item skus
AoPSAPI_Exception::INVALID_PARAMETER - An invalid item sku was passed in
AoPSAPI_Exception::INVALID_PERMISSIONS - API Application does not have permission to submit order
Example
require_once 'AoPSAPI.php';
$api = new AoPSAPI('<api_key>', '<secret_key>');
try
{
$result = $api->product->get_weight('intro:algebra');
echo 'The weight of Introduction to Algebra is ' . $result . ' ounces.
';
$result = $api->product->get_weight(array('intro:algebra', 'intro:algebra:solutions'));
echo 'The combined weight of Introduction to Algebra and its solutions manual is ' .
$result . ' ounces.
';
}
catch (AoPSAPI_Exception $ex)
{
echo $ex->getMessage() . "
";
}
Output
The weight of Introduction to Algebra is 53 ounces. The combined weight of Introduction to Algebra and its solutions manual is 79 ounces.