# Amazon onebox fails on my site, but works here

**URL:** <https://meta.discourse.org/t/amazon-onebox-fails-on-my-site-but-works-here/41609>\
**Category:** Bug\
**Created:** [March 27, 2016, 2:25am UTC](https://meta.discourse.org/t/amazon-onebox-fails-on-my-site-but-works-here/41609 "2016-03-27T02:25:35Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [March 27, 2016, 7:30pm UTC](https://meta.discourse.org/t/amazon-onebox-fails-on-my-site-but-works-here/41609/7 "2016-03-27T19:30:05Z")

</div>

I’ve just tested this on a live Discourse instance, one that is running a little behind latest `v1.5.0.beta12 +135` - I will update and test again when I get chance… but…

Although I’ve white-listed the domain `www.amazon.co.uk` and restarted (not rebuild) Discourse I see the same results as @mcwumbly mentions in Chrome Dev Tools.

I’ve verified that I can connect to the URL:

```plaintext
root@forum:~# curl http://www.amazon.co.uk/Belkin-BSV103-SurgeCube-Protector-Charging/dp/B00P2GW7MG -o deleteme.html --verbose
* Hostname was NOT found in DNS cache
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
  0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 176.32.108.186...
* Connected to www.amazon.co.uk (176.32.108.186) port 80 (#0)
> GET /Belkin-BSV103-SurgeCube-Protector-Charging/dp/B00P2GW7MG HTTP/1.1
> User-Agent: curl/7.35.0
> Host: www.amazon.co.uk
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sun, 27 Mar 2016 18:07:47 GMT
* Server Server is not blacklisted
< Server: Server
< pragma: no-cache
< x-amz-id-1: 1QKR29Z3J28QM1BPTS6V
< p3p: policyref="https://www.amazon.co.uk/w3c/p3p.xml",CP="CAO DSP LAW CUR ADM IVAo IVDo CONo OTPo OUR DELi PUBi OTRi BUS PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA HEA PRE LOC GOV OTC "
< cache-control: no-cache, no-transform
< x-frame-options: SAMEORIGIN
< expires: -1
< x-ua-compatible: IE=edge
< Vary: Accept-Encoding,User-Agent
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
<
{ [data not shown]
100 439k 0 439k 0 0 496k 0 --:--:-- --:--:-- --:--:-- 496k
* Connection #0 to host www.amazon.co.uk left intact
root@forum:~#

```

And again it embeds fine here on meta:

> **[Belkin Extension Lead with USB Slots x 2 (2.4 A Shared), 4 Way/4 Plug Extension,...](https://www.amazon.co.uk/Belkin-BSV401af2M-Protection-Extension-Charging/dp/B00OE43I9S)**
>
> Safeguard your electronics with this 4-outlet power strip featuring 2 USB ports for charging. Surge protection and a 2m cable provide convenient, reliable power.

And only the standard plugins for me:

 ![](https://global.discourse-cdn.com/meta/original/3X/6/5/6590acaea95122f21cfba5e65b5ab051586dd5d4.png)

Doing a bit of debugging I tried executing the following:

```plaintext
[4] pry(main)> url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
review}" == preview.t=> "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
[5] pry(main)> preview = Onebox.preview(url)
=> #<Onebox::Preview:0x007f2f1a97f270
 @cache=
  #<Moneta::Expires:0x007f2f1674ca38
   @adapter=
    #<Moneta::Transformer::JsonPrefixKeyJsonValue:0x007f2f1674cab0
     @adapter=#<Moneta::Adapters::Memory:0x007f2f16795710 @backend={}>,
     @features=[:increment, :create],
     @prefix="">,
   @default_expires=nil>,
 @engine_class=Onebox::Engine::AmazonOnebox,
 @options=
  #<OpenStruct cache=#<Moneta::Expires:0x007f2f1674ca38 @adapter=#<Moneta::Transformer::JsonPrefixKeyJsonValue:0x007f2f1674cab0 @adapter=#<Moneta::Adapters::Memory:0x007f2f16795710 @backend={}>, @prefix="", @features=[:increment, :create]>, @default_expires=nil>, connect_timeout=5, timeout=10, load_paths=["/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/onebox-1.5.35/templates"], twitter_client=TwitterApi>,
 @url="http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2">
[6] pry(main)> "#{preview}" == preview.to_s
NoMethodError: undefined method `value' for nil:NilClass
from /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/onebox-1.5.35/lib/onebox/engine/amazon_onebox.rb:38:in `image'
[7] pry(main)> 

```

> <https://github.com/discourse/onebox/blob/63501e1096d2b52810d8465e3239be7f9d87bc02/lib/onebox/engine/amazon_onebox.rb#L38>

After executing this I can see now `raw` contains a value when viewing the object `preview` (too large to paste here)

This seems to indicate that:

1. the expected HTML response has changed
2. the parsing of the HTML doesn’t correctly catch an error which occurs during the “parsing” of the response.
3. an error is not being surfaced to the Discourse logs

---

_[View the full topic](https://meta.discourse.org/t/amazon-onebox-fails-on-my-site-but-works-here/41609)._
