amazon-web-servicesapiamazon-product-apiamazon-product-advertising-api

Amazon Cart API - CartCreate Response


I am using the Amazon Product Advertising API. I am using the CartCreate operation to create a remote shopping cart and add two items into it.

Here is my CartCreate operation:

http://webservices.amazon.com/onca/xml?
AWSAccessKeyId=12AWSAccessKey12
AssociateTag=myweb-no
Item.1.ASIN=erq1
Item.1.Quantity=1
Operation=CartCreate
Service=AWSECommerceService
Timestamp=timeanddate
Signature=generatedsignature

Solution

  • This is a XML over HTTP API, so what you get back is XML. Here is an example response:

    <Cart>
      <Request>
        <IsValid>True</IsValid>
        <CartCreateRequest>
          <Items>
            <Item>
              <ASIN>B000062TU1</ASIN>
              <Quantity>2</Quantity>
            </Item>
          </Items>
        </CartCreateRequest>
      </Request>
      <CartId>102-5014548-4857758</CartId>
      <HMAC>O2p9hhZwJShnp6ZDWvZDO6FhpAI=</HMAC>
      <URLEncodedHMAC>O2p9hhZwJShnp6ZDWvZDO6FhpAI=</URLEncodedHMAC>
    
    <PurchaseURL>https://www.amazon.com/gp/cart/aws-merge.html?cart-id=102-5014548-4857758%26associate-id=ws%26hmac=O2p9hhZwJShnp6ZDWvZDO6FhpAI=%26AWSAccessKeyId=1VMEXAMPLEW9C02</PurchaseURL>
      <SubTotal>
        <Amount>1994</Amount>
        <CurrencyCode>USD</CurrencyCode>
        <FormattedPrice>$19.94</FormattedPrice>
      </SubTotal>
      <CartItems>
          <SubTotal>
            <Amount>1994</Amount>
            <CurrencyCode>USD</CurrencyCode>
            <FormattedPrice>$19.94</FormattedPrice>
          </SubTotal>
        <CartItem>
          <CartItemId>U31XY1DHZEGCTB</CartItemId>
          <ASIN>B000062TU1</ASIN>
          <Quantity>2</Quantity>
          <Title>Harry Potter and the Sorcerer's Stone (Full Screen Edition) (Harry Potter 1)</Title>
          <ProductGroup>DVD</ProductGroup>
          <Price>
            <Amount>997</Amount>
            <CurrencyCode>USD</CurrencyCode>
            <FormattedPrice>$9.97</FormattedPrice>
          </Price>
          <ItemTotal>
            <Amount>1994</Amount>
            <CurrencyCode>USD</CurrencyCode>
            <FormattedPrice>$19.94</FormattedPrice>
          </ItemTotal>
        </CartItem>
      </CartItems>
    </Cart>
    

    You need to take the Purchase URL from the response above, and create a link on your site to allow the use to go to Amazon to complete their purchase. The Purchase URL from the example response looks like this

    <PurchaseURL>https://www.amazon.com/gp/cart/aws-merge.html?cart-id=102-5014548-4857758%26associate-id=ws%26hmac=O2p9hhZwJShnp6ZDWvZDO6FhpAI=%26AWSAccessKeyId=1VMEXAMPLEW9C02</PurchaseURL>
    

    You can alternatively just use a HTML Add to cart form to create your remote cart. This is a more basic way of doing things but it gives you less control as when you post this form the user will be taken straight to the Amazon website. Here is an example form:

    <form method="GET" action="https://www.amazon.com/gp/aws/cart/add.html"> 
    <input type="hidden" name="AWSAccessKeyId" value="Access Key ID" /><br/> 
    <input type="hidden" name="AssociateTag" value="Associate Tag" /><br/> 
    <p>One Product<br/> 
    ASIN:<input type="text" name="ASIN.1"/><br/> 
    Quantity:<input type="text" name="Quantity.1"/><br/> 
    <p>Another Product<br/> 
    ASIN:<input type="text" name="ASIN.2"/><br/> 
    Quantity:<input type="text" name="Quantity.2"/><br/> 
    </p> 
    <input type="submit" name="add" value="add" /> 
    </form>