# Using Javascript fetch()?

**URL:** <https://forum.alpaca.markets/t/using-javascript-fetch/302>\
**Category:** Alpaca Integration Applications\
**Created:** [September 21, 2019, 9:07pm UTC](https://forum.alpaca.markets/t/using-javascript-fetch/302 "2019-09-21T21:07:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![erandall](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@erandall](https://forum.alpaca.markets/u/erandall)\
**Post date:** [September 21, 2019, 9:07pm UTC](https://forum.alpaca.markets/t/using-javascript-fetch/302/1 "2019-09-21T21:07:13Z")

</div>

Hi guys,

Rather than using the “alpacahq/alpaca-trade-api” I’d prefer to use only be using fetch. I have been unsuccessful in getting anything other than “status: 401”, " statusText: Unauthorized" as a response.

So I was wondering how I should format my fetch() request to get a proper response. Here’s a code snippet that I’ve just tried with no luck.

Granted this is a bad example, yes, but I haven’t been able to find any documentation using fetch()

```
 fetch("https://paper-api.alpaca.markets/v2/positions", {
		"method": "GET",
		"APCA-API-KEY-ID": "mykeyhere",
		"APCA-API-SECRET-KEY": "mysecretkeyhere"
	})

```

Should I fetch to something like: “[https://paper-api.alpaca.markets/v2/positions?apca-api-key-id=mykey&apca-api-secret-key=mysecretkey](https://paper-api.alpaca.markets/v2/positions?apca-api-key-id=mykey&apca-api-secret-key=mysecretkey)”?

How would I correct this issue?

---

<div class="post-metadata">

**Author:** ![kris](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/kris/32/163_2.png) [@kris](https://forum.alpaca.markets/u/kris)\
**Post date:** [September 23, 2019, 5:49am UTC](https://forum.alpaca.markets/t/using-javascript-fetch/302/2 "2019-09-23T05:49:48Z")

</div>

Seems like you might have a misconception of how http headers work, since you dont say what programming language you are using, since it looks like java look into [https://github.com/mainstringargs/alpaca-java](https://github.com/mainstringargs/alpaca-java)

---

<div class="post-metadata">

**Author:** ![Rathe001](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/rathe001/32/215_2.png) [@Rathe001](https://forum.alpaca.markets/u/Rathe001)\
**Post date:** [October 28, 2019, 1:32pm UTC](https://forum.alpaca.markets/t/using-javascript-fetch/302/3 "2019-10-28T13:32:54Z")

</div>

You are close. Changing your code to the following seems to work for me:

```
const positions = await fetch('https://paper-api.alpaca.markets/v2/positions', {
  'method': 'GET',
  'headers': {
    'content-type': 'application/json',
    'APCA-API-KEY-ID': API_KEY,
    'APCA-API-SECRET-KEY': API_SECRET_KEY,
  }
})
```
