# fetch error in notebook

**URL:** <https://talk.observablehq.com/t/fetch-error-in-notebook/3330>\
**Category:** Help\
**Created:** [May 20, 2020, 6:53am UTC](https://talk.observablehq.com/t/fetch-error-in-notebook/3330 "2020-05-20T06:53:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnprock](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dnprock](https://talk.observablehq.com/u/dnprock)\
**Post date:** [May 20, 2020, 6:53am UTC](https://talk.observablehq.com/t/fetch-error-in-notebook/3330/1 "2020-05-20T06:53:20Z")

</div>

Hello,

I’m writing a fetch query but get an error in the notebook. I check the browser’s Network tab. The request returns 200 with a valid response. But in the notebook, I get an error:

`SyntaxError: Unexpected end of input`

```
fetch("https://www.bitmex.com/api/v1/trade?symbol=.BVOL&count=100&columns=price", {
  headers: {"content-type": "application/json"},
  mode: "no-cors"
}).then(response => {
  return response.json();
});

```

What is the difference between the browser’s network request and the notebook?

Thanks.

---

<div class="post-metadata">

**Author:** ![radames](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/radames/32/1699_2.png) [@radames](https://talk.observablehq.com/u/radames)\
**Post date:** [May 21, 2020, 5:35am UTC](https://talk.observablehq.com/t/fetch-error-in-notebook/3330/2 "2020-05-21T05:35:11Z")

</div>

Hi @dnprock, it seems like they don’t offer CORS on their public API for security reasons.

> <https://github.com/BitMEX/api-connectors/issues/206>
>
> Failed to load https://testnet.bitmex.com/api/v1/user/walletHistory: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested...

But you can use a proxy. I’ve setup one for you on glitch. You can run this on Observable now, there will be a few seconds to warmup glitch

```auto
data = await fetch(
  "https://bitmex-proxy.glitch.me/api/v1/trade?symbol=.BVOL&count=100&columns=price"
).then(r => r.json())

```

Here is the source code on glitch

> **[Glitch](https://glitch.com/edit/#!/bitmex-proxy?path=server.js:1:0)**
>
> Combining automated deployment, instant hosting & collaborative editing, Glitch gets you straight to coding so you can build full-stack web apps, fast

---

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [May 21, 2020, 5:39am UTC](https://talk.observablehq.com/t/fetch-error-in-notebook/3330/3 "2020-05-21T05:39:45Z")

</div>

Heh, seeing your comment jogged my memory.

> [@JSON from API address](https://talk.observablehq.com/t/json-from-api-address/1780):
>
> when I go to this [API address](https://www.bitmex.com/api/v1/trade/bucketed?binSize=1h&partial=false&count=750&symbol=XBT&reverse=true&endTime=2019-03-17T00:00:00.000Z) with my browser I can visualise the JSON file related to it. I tried to access it by Observable using the [cors-anywhere.herokuapp.com](http://cors-anywhere.herokuapp.com) but I get a SyntaxError: Unexpected end of JSON input. here is notebook: Any chance to make it work? Thanks

---

<div class="post-metadata">

**Author:** ![dnprock](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dnprock](https://talk.observablehq.com/u/dnprock)\
**Post date:** [May 24, 2020, 6:06am UTC](https://talk.observablehq.com/t/fetch-error-in-notebook/3330/4 "2020-05-24T06:06:34Z")

</div>

@radames @bgchen thanks for the reference.
