Amazon Add Products to Cart and Review

Site amazon.comTask add-products-to-cart-and-reviewVersion v8Updated Sep 16, 2026Category ecommerce

Resolve products from Amazon search queries, add selected products to the cart, and return structured item, condition, price, shipping, seller, delivery, return-policy, destination, and cart-total details. This skill was captured from a live agent session on amazon.com and is published here as a reusable recipe for agents.

NoteSelectors and URL schemes drift as sites change. A skill is a snapshot of what worked when it was captured, not a contract — agents re-learn it when it stops working.

Add Amazon products selected from direct search results to the cart and return structured product, condition, seller, price, shipping, delivery, return-policy, destination, and numeric cart-total details.

Use Cases

  • Add products matching exact title, category, price, availability, seller, condition, rating, and Prime constraints.
  • Add products using Amazon URL filters for price, rating, department, seller, 4K/UHD, or free shipping.
  • Compare delivery, seller, return eligibility, and condition before adding.
  • Add two or more different ASINs found across multiple result pages.
  • Report ASINs, canonical product URLs, cart contents, and cart subtotal or total.

Automation Flow

  1. Build and goto https://www.amazon.com/s?k={url-encoded-query}&i={department}&s={sort}&page={page}&rh={filters}. Use direct rh filters when their values are known. For seller, 4K/UHD, or free-shipping facets whose values are unknown, load the broad search once, read the matching refinement anchor href under #s-refinements, then goto that href; do not guess opaque refinement values.
  2. Evaluate the search page:
(() => {
const clean=s=>String(s||'').replace(/\s+/g,' ').trim()||null;
const cards=[...document.querySelectorAll('div[data-component-type="s-search-result"][data-asin]')];const seen=new Set();
const results=cards.map((card,index)=>{const asin=card.dataset.asin;if(!asin||seen.has(asin))return null;seen.add(asin);const text=clean(card.innerText)||'';const p=card.querySelector('.a-price:not(.a-text-price) .a-offscreen'),r=card.querySelector('.a-icon-alt');return {rank:index+1,asin,title:clean(card.querySelector('h2')?.innerText||card.querySelector('img.s-image')?.alt),price:clean(p?.textContent),rating:r?parseFloat(r.textContent):null,primeEligible:/\bPrime\b/i.test(text)||!!card.querySelector('[data-cy="delivery-recipe"] .prime-brand-color,i.a-icon-prime'),sponsored:!!card.querySelector('.puis-sponsored-label-text,.s-sponsored-label-text,[aria-label*="Sponsored"],[data-component-type="sp-sponsored-result"]'),availability:/in stock|available/i.test(text),directAddButton:!!card.querySelector('input[name="submit.addToCart"],input[name="submit.add-to-cart"],#add-to-cart-button'),url:`https://www.amazon.com/dp/${asin}`};}).filter(Boolean);
const body=document.body.innerText||'';return {url:location.href,organicCount:cards.length,results,noResults:/no results for|did not match any products|we couldn't find any results/i.test(body)||cards.length===0};
})()
  1. Request page={N} until enough distinct qualifying organic ASINs are found; deduplicate by ASIN and exclude sponsored cards. Verify each candidate at https://www.amazon.com/dp/{asin}?th=1.
  2. On each product page, evaluate:
(() => {
const clean=s=>String(s||'').replace(/\s+/g,' ').trim()||null;const pick=(...q)=>q.map(s=>document.querySelector(s)?.innerText?.trim()).find(Boolean)||null;const asin=document.querySelector('#ASIN')?.value||location.pathname.match(/\/dp\/([A-Z0-9]{10})/i)?.[1]||null;const rows=[...document.querySelectorAll('#tabular-buybox tr,#productDetails_detailBullets_sections1 tr,#detailBullets_feature_div li')].map(x=>clean(x.innerText)).filter(Boolean);const right=clean(document.querySelector('#rightCol')?.innerText)||'';const offer=/Shipper\s*\/\s*Seller[^\n]*/i.exec(right)?.[0]||null;return {asin,url:location.href,title:clean(pick('#productTitle','#title')),condition:rows.find(x=>/condition|renewed|refurbished|new|used/i.test(x))||clean(pick('#condition')),price:clean(pick('#corePrice_feature_div .a-offscreen','#corePriceDisplay_desktop_feature_div .a-offscreen','#price_inside_buybox','#priceblock_ourprice')),availability:clean(pick('#availability span','#outOfStock')),seller:clean(pick('#sellerProfileTriggerId','#merchant-info'))||offer,shipsFrom:clean(pick('#tabular-buybox .tabular-buybox-text[tabular-attribute-name="Ships from"]','#tabular-buybox .tabular-buybox-text')),soldBy:clean(pick('#tabular-buybox .tabular-buybox-text[tabular-attribute-name="Sold by"]','#sellerProfileTriggerId','#merchant-info'))||offer,delivery:[...document.querySelectorAll('#mir-layout-DELIVERY_BLOCK-slot-PRIMARY_DELIVERY_MESSAGE_LARGE span,#deliveryBlockMessage span,#fast-track-message')].map(x=>clean(x.innerText)).filter(Boolean),returns:[...document.querySelectorAll('#creturns-policy-anchor-text,#productSupportAndReturns,#returns-policy-anchor-text')].map(x=>clean(x.innerText)).filter(Boolean),addButton:!!document.querySelector('#add-to-cart-button,input[name="submit.add-to-cart"],input[name="submit.addToCart"]')};
})()
  1. Keep only in-stock products satisfying the requested category, price, rating, seller, 4K/UHD, and free-delivery rules. Click the active #add-to-cart-button, input[name='submit.add-to-cart'], or input[name='submit.addToCart']; if no confirmation or cart-count change appears, reload the same product URL and submit the active control once. If a protection-plan sheet appears, click visible No thanks, input[value='No thanks'], or input[aria-labelledby='attachSiNoCoverage-announce'].
  2. Goto https://www.amazon.com/gp/cart/view.html and evaluate:
(() => {
const clean=s=>String(s||'').replace(/\s+/g,' ').trim()||null;const uniq=a=>[...new Set(a.filter(Boolean))];const lines=(document.body.innerText||'').split(/\n+/).map(clean).filter(Boolean);const rows=[...document.querySelectorAll('#sc-active-cart [data-asin],#sc-active-cart .sc-list-item,[data-asin]')];const items=[],seen=new Set();for(const row of rows){const asin=row.getAttribute('data-asin')||row.querySelector('[data-asin]')?.getAttribute('data-asin');if(!asin||seen.has(asin))continue;seen.add(asin);const box=row.closest('.sc-list-item,[data-item-index],.sc-list-item-content')||row;const text=clean(box.innerText)||'';const condition=(text.match(/(?:condition|item condition)\s*:\s*([^\n]+)/i)||[])[1]||((text.match(/\b(refurbished|renewed|new|used)\b/i)||[])[1]||null);items.push({asin,title:clean(box.querySelector('.sc-product-title,.a-truncate-full,.sc-grid-item-product-title,a[href*="/dp/"]')?.innerText||box.querySelector('img')?.alt),condition:clean(condition),price:clean(box.querySelector('.sc-item-price,.sc-product-price,.sc-price')),quantity:clean(box.querySelector('input[name*="quantity"]')?.value||box.querySelector('.sc-quantity-text')?.innerText),delivery:clean(box.querySelector('.sc-item-delivery,.sc-delivery-message')),seller:clean(box.querySelector('.sc-item-seller')),text:text.slice(0,2500)});}const money=x=>/[$£€¥]|USD|subtotal|total/i.test(x);const matching=re=>uniq(lines.filter(x=>re.test(x)&&money(x))).sort((a,b)=>a.length-b.length);const totalLines=matching(/current total|grand total|order total|estimated total|cart total|total/i);const subtotalLines=matching(/amazon subtotal|cart subtotal|subtotal/i);return {url:location.href,items,cartCount:clean(document.querySelector('#nav-cart-count')?.textContent),subtotal:subtotalLines.find(x=>/[$£€¥]|USD/i.test(x))||null,total:totalLines.find(x=>/current total|grand total|order total|estimated total|cart total/i.test(x))||totalLines[0]||null,destination:clean(document.querySelector('#glow-ingress-line2')?.innerText||document.querySelector('#nav-global-location-popover-link')?.innerText)||lines.find(x=>/deliver to|shipping address|ship to/i.test(x))||null,shipping:uniq(lines.filter(x=>/delivery|arrives|shipping|ships from|sold by|free shipping|delivery estimate/i.test(x))),returns:uniq(lines.filter(x=>/return|free returns|return window|eligible for return|refund/i.test(x)))};
})()

Params

ParamWhat it doesExample value
queryAmazon search phrase used to resolve products4K computer monitor
selection_criteriaTitle, category, price, availability, seller, condition, rating, Prime, shipping, and sponsorship rules4K, under $250, at least 4 stars, sold by Amazon.com, free delivery
asinOpaque product identifier returned by searchB08G1ZBKGP
quantityQuantity to add for a selected product1
pageSearch-results page to request and stitch2
filtersOptional Amazon rh filter fragmentsp_36:-25000,p_72:1248879011
seller_filterLive seller-refinement href or confirmed rh fragmentp_6:ATVPDKIKX0DER
rating_filterAmazon 4 Stars & Up refinement; post-filter for exact minimump_72:1248879011
uhd_filterLive 4K UHD 2160p refinement href or fragmentp_n_feature_browse-bin:...
free_shipping_filterLive Free Shipping by Amazon refinement href or fragmentp_n_g-1003195531111:23746030011
cart_urlDirect cart URLhttps://www.amazon.com/gp/cart/view.html

Possible Friction Points

TriggerAction
Initial homepage navigation times out or loads incompletelySkip the homepage and goto the direct search URL; retry once if needed.
Seller, 4K/UHD, or free-shipping click leaves the URL unchangedRead that facet anchor's href and goto the extracted destination directly.
Required matches span multiple result pagesRequest page={N}, deduplicate by ASIN, and continue until enough matches are found or pages are exhausted.
Search returns sponsored fallback products or no organic cardsExclude sponsored:true; treat organicCount:0 as no organic results.
Search-card availability is unreliableOpen the product page and require a positive availability value before adding.
Amazon exposes only 4 Stars & Up for a five-star requestUse p_72:1248879011, post-filter ratings, and report that the facet is not exact.
Candidate seller is not the required seller or tabular seller selectors are emptyExclude the candidate unless right-side offer text confirms the required seller; parse #rightCol text matching Shipper / Seller.
Product page lacks a condition labelReturn condition:null; do not infer condition.
Add-to-cart click produces no confirmation or cart-count changeReload the same product page and click the active add-to-cart control once; stop if authentication is required.
Product page lacks Add to cartTry both submit.add-to-cart and submit.addToCart; otherwise mark unavailable for cart addition.
Protection-plan sheet appears after addingClick visible No thanks, input[value='No thanks'], or input[aria-labelledby='attachSiNoCoverage-announce'].
Cart has multiple DOM representations of one itemDeduplicate cart rows by ASIN.
Cart total label lacks a numeric amountPrefer the shortest currency-bearing Current Total, Grand Total, Order Total, Estimated Total, or Cart Total line; return null if absent.
Cart destination is absent from structured selectorsExtract visible Deliver to or shipping-address lines; report null when absent.
Robot Check, CAPTCHA, transient error, or sign-in wall replaces the pageReload once for a transient error; otherwise stop and return blocked or authentication-required status.

Call it

GET https://production-sfo.browserless.io/skills?token=TOKEN-HERE&domain=amazon.com&task=add-products-to-cart-and-review