# Unknown API key error using nodejs api

**URL:** <https://forum.alpaca.markets/t/unknown-api-key-error-using-nodejs-api/4718>\
**Category:** Alpaca Account Troubleshooting\
**Created:** [March 1, 2021, 4:22pm UTC](https://forum.alpaca.markets/t/unknown-api-key-error-using-nodejs-api/4718 "2021-03-01T16:22:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_S](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/chris_s/32/2125_2.png) [@Chris\_S](https://forum.alpaca.markets/u/Chris_S)\
**Post date:** [March 1, 2021, 4:22pm UTC](https://forum.alpaca.markets/t/unknown-api-key-error-using-nodejs-api/4718/1 "2021-03-01T16:22:18Z")

</div>

I was using the nodejs api for alpaca for months without a problem and today I started getting “unknown api key” errors. I recreated a new pair of keys but the error remains. Anyone can help me out here?

---

<div class="post-metadata">

**Author:** ![Peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Peter](https://forum.alpaca.markets/u/Peter)\
**Post date:** [March 1, 2021, 5:32pm UTC](https://forum.alpaca.markets/t/unknown-api-key-error-using-nodejs-api/4718/2 "2021-03-01T17:32:56Z")

</div>

I’m assuming this is a Polygon issue. Alpaca discontinued its contract with Polygon over the weekend. This means your Alpaca keys no longer work to access Polygon’s endpoints.

A temporary solution is to create a Polygon account and sign up for their $199/month developer plan using the “ALPACA” coupon code for a free month.

---

<div class="post-metadata">

**Author:** ![Chris\_S](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/chris_s/32/2125_2.png) [@Chris\_S](https://forum.alpaca.markets/u/Chris_S)\
**Post date:** [March 1, 2021, 5:52pm UTC](https://forum.alpaca.markets/t/unknown-api-key-error-using-nodejs-api/4718/3 "2021-03-01T17:52:46Z")

</div>

Thanks for your reply Peter. Thats what I initially thought as well and then I have deactivated polygon in the nodejs alpaca api but I still get unknown api key response.

Are you familiar with the nodejs alpaca api?

This is how I initiate it:

```
	this.alpaca = new Alpaca({
		keyId: apikey,
		secretKey: apisecret,
		paper: false,
		usePolygon: false
	});
```

---

<div class="post-metadata">

**Author:** ![Chris\_S](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/chris_s/32/2125_2.png) [@Chris\_S](https://forum.alpaca.markets/u/Chris_S)\
**Post date:** [March 1, 2021, 6:41pm UTC](https://forum.alpaca.markets/t/unknown-api-key-error-using-nodejs-api/4718/4 "2021-03-01T18:41:37Z")

</div>

quick update, the nodejs api hat some preserved functions that still used polygon. I changed them and got a step further but now I get an error stating “account is not authorized to trade”. Anyone know where this is coming from?

2021-03-01T18:38:03.429857+00:00 app[web.1]: error: { code: 40310000, message: ‘account is not authorized to trade’ },  
2021-03-01T18:38:03.429858+00:00 app[web.1]: options: {  
2021-03-01T18:38:03.429858+00:00 app[web.1]: method: ‘POST’,  
2021-03-01T18:38:03.429859+00:00 app[web.1]: uri: ‘[https://api.alpaca.markets/v2/orders](https://api.alpaca.markets/v2/orders)’,  
2021-03-01T18:38:03.429859+00:00 app[web.1]: qs: {},  
2021-03-01T18:38:03.429859+00:00 app[web.1]: headers: {  
2021-03-01T18:38:03.429860+00:00 app[web.1]: ‘content-type’: ‘application/json’,  
2021-03-01T18:38:03.429860+00:00 app[web.1]: ‘APCA-API-KEY-ID’: ‘mykey’,  
2021-03-01T18:38:03.429861+00:00 app[web.1]: ‘APCA-API-SECRET-KEY’: ‘mysecret’  
2021-03-01T18:38:03.429861+00:00 app[web.1]: },

---

<div class="post-metadata">

**Author:** ![Peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Peter](https://forum.alpaca.markets/u/Peter)\
**Post date:** [March 1, 2021, 6:46pm UTC](https://forum.alpaca.markets/t/unknown-api-key-error-using-nodejs-api/4718/5 "2021-03-01T18:46:08Z")

</div>

Glad you figured that out. Yeah, it looks like the JS API’s `usePolygon` parameter only dictates which websocket to use, so it doesn’t fix the issue with Polygon’s REST API.

As for “account is not authorized to trade”, I’m guessing [this thread](https://forum.alpaca.markets/t/live-account-not-authorized-to-trade/4715) is related.

---

<div class="post-metadata">

**Author:** ![Chris\_S](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/chris_s/32/2125_2.png) [@Chris\_S](https://forum.alpaca.markets/u/Chris_S)\
**Post date:** [March 1, 2021, 6:55pm UTC](https://forum.alpaca.markets/t/unknown-api-key-error-using-nodejs-api/4718/6 "2021-03-01T18:55:14Z")

</div>

Thank you Peter, I replied into that thread asking for help. Unfortunatly, it didnt contain any fix or cause for that issue. The author just posted that it was fixed but not how. We ll see…
