apiamazon-product-apiunit-conversion

Unit conversion - Amazon API


Amazon API returns strange dimensions. On the website, they have displayed:

Product Dimensions: 8.7 x 7.9 x 0.6 inches ; 1.8 ounces
Shipping Weight: 4 ounces

while the API returns:

[ItemDimensions] => Array
(
    [Height] => 59
    [Length] => 866
    [Weight] => 11
    [Width] => 787
)

[PackageDimensions] => Array
(
  [Height] => 50
  [Length] => 700
  [Weight] => 25
  [Width] => 200
)

I'm not sure what unit that is. I confirmed twice to make sure its the same product.

I need to convert it to mm and grams. 22cm or 220mm is 8.7 inches so no clue whats 50 or 59 thats being returned. Same for weight.


Solution

  • The product dimensions are in inches. Their display is achieved by dividing the stored values by 100 and adjusting the first place after the period.

    Length -> stored as 866 - displayed as 8.7
    Width  -> stored as 787 - displayed as 7.9
    Height -> stored as 59  - displayed as 0.6
    

    You can transfer this to the metric system by converting. 1 inch = 2.54 centimetres.

    Take Length

    866 / 100 = 8.66
    8.66 * 2.54 = 21.9962 centimetres. 
    Display as 22 cm, or 21.99 cm, etc...
    

    The weight is stored in pounds, but displayed in ounces. 1 pound = 16 ounces, or 0.11 pounds = 1.76 ounces. 1.76 is adjusted to 1.8.

    Since 1 pound = 453.592 grams, you can transfer by doing

    0.11 * 453.492 = 49.89512 grams. 
    Display as 49 g, or 49.9 g, etc...