Using Javascript fetch()?

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("", {
		"method": "GET",
		"APCA-API-KEY-ID": "mykeyhere",
		"APCA-API-SECRET-KEY": "mysecretkeyhere"

Should I fetch to something like: “”?

How would I correct this issue?

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

1 Like

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

const positions = await fetch('', {
  'method': 'GET',
  'headers': {
    'content-type': 'application/json',
1 Like