# I'm trying to run starter locally and I get 401 unauthorized "invalid api key"

**URL:** <http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161>\
**Category:** API / Development\
**Created:** [11 February 2022 09:46 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161 "2022-02-11T09:46:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkbaseer](http://community.tradly.app/user_avatar/community.tradly.app/jkbaseer/32/1296_2.png) [@jkbaseer](http://community.tradly.app/u/jkbaseer)\
**Post date:** [11 February 2022 09:46 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/1 "2022-02-11T09:46:10Z")

</div>

@AhsaUllah could you share why?

@collin:  
Could you share which started kit you are trying and also you have pasted your api key in env files?

---

<div class="post-metadata">

**Author:** ![ccc](http://community.tradly.app/user_avatar/community.tradly.app/ccc/32/132_2.png) [@ccc](http://community.tradly.app/u/ccc)\
**Post date:** [11 February 2022 09:52 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/2 "2022-02-11T09:52:15Z")

</div>

The marketplace starter, Butterfly. Yes I have and it shows my api key inside the Authorization header so I know it’s working.

---

<div class="post-metadata">

**Author:** ![AhsaUllah](http://community.tradly.app/letter_avatar_proxy/v4/letter/a/c5a1d2/32.png) [@AhsaUllah](http://community.tradly.app/u/AhsaUllah)\
**Post date:** [11 February 2022 10:11 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/3 "2022-02-11T10:11:42Z")

</div>

In the env folder, you need to set 3 variables,

1. ENVIRONMENT = “production / sandbox”
2. API\_KEY = “Your API key”
3. SITE\_URL =“your domain name”

Note: If you have a production API key then need to pass in 1st variable **“production”** value or if you have a sandbox API key need to pass the **"sandbox "** value.  
3rd variable is optional.

---

<div class="post-metadata">

**Author:** ![ccc](http://community.tradly.app/user_avatar/community.tradly.app/ccc/32/132_2.png) [@ccc](http://community.tradly.app/u/ccc)\
**Post date:** [11 February 2022 10:20 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/4 "2022-02-11T10:20:37Z")

</div>

Thanks. When I toggle between production and sandbox, I seem to get the same API key. am i missing something?

---

<div class="post-metadata">

**Author:** ![jkbaseer](http://community.tradly.app/user_avatar/community.tradly.app/jkbaseer/32/1296_2.png) [@jkbaseer](http://community.tradly.app/u/jkbaseer)\
**Post date:** [11 February 2022 10:40 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/5 "2022-02-11T10:40:49Z")

</div>

It shouldn’t show the same API key. We are checking why this is happening for you.

---

<div class="post-metadata">

**Author:** ![jkbaseer](http://community.tradly.app/user_avatar/community.tradly.app/jkbaseer/32/1296_2.png) [@jkbaseer](http://community.tradly.app/u/jkbaseer)\
**Post date:** [11 February 2022 11:08 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/6 "2022-02-11T11:08:52Z")

</div>

Hi,  
We have checked, there seems to be some cookie issue on our recent update, so it’s not refreshing.

Can you use production key for now?

In 2-3hours, we are providing a minor changes that will fix this issues.

---

<div class="post-metadata">

**Author:** ![ccc](http://community.tradly.app/user_avatar/community.tradly.app/ccc/32/132_2.png) [@ccc](http://community.tradly.app/u/ccc)\
**Post date:** [11 February 2022 11:33 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/7 "2022-02-11T11:33:03Z")

</div>

I’m unable to switch the sdk from calling api.dev to production api url. This must be using the NODE\_ENV variable to choose. When I set the NODE\_ENV inside the package.json “dev” command it is throwing me an error. So I’m not able to use the production api key.

Would be better if sdk takes a config param to set the environment.

---

<div class="post-metadata">

**Author:** ![AhsaUllah](http://community.tradly.app/letter_avatar_proxy/v4/letter/a/c5a1d2/32.png) [@AhsaUllah](http://community.tradly.app/u/AhsaUllah)\
**Post date:** [11 February 2022 12:23 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/8 "2022-02-11T12:23:17Z")

</div>

You don’t need to touch inside the packege.json file.  
Change API\_KEY and ENVIRONMENT variables from env file.  
When you change anything in the env folder you need to close your terminal and rerun the project.

---

<div class="post-metadata">

**Author:** ![jkbaseer](http://community.tradly.app/user_avatar/community.tradly.app/jkbaseer/32/1296_2.png) [@jkbaseer](http://community.tradly.app/u/jkbaseer)\
**Post date:** [11 February 2022 13:37 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/9 "2022-02-11T13:37:00Z")

</div>

@ccc the sandbox issue is fixed. You may able to find the sandbox api key as well.

---

<div class="post-metadata">

**Author:** ![ccc](http://community.tradly.app/user_avatar/community.tradly.app/ccc/32/132_2.png) [@ccc](http://community.tradly.app/u/ccc)\
**Post date:** [13 February 2022 11:41 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/10 "2022-02-13T11:41:34Z")

</div>

![153751333-641e40f5-f48b-4329-b941-fb0649109ee4](https://forum.tradly.app/uploads/default/original/1X/fdf210666ab0b480046c507ba3b7ea270e105777.png)

Still not working with sandbox key. ☹

---

<div class="post-metadata">

**Author:** ![AhsaUllah](http://community.tradly.app/letter_avatar_proxy/v4/letter/a/c5a1d2/32.png) [@AhsaUllah](http://community.tradly.app/u/AhsaUllah)\
**Post date:** [14 February 2022 12:27 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/11 "2022-02-14T12:27:59Z")

</div>

![image](https://forum.tradly.app/uploads/default/original/1X/d2f36b543367a8cab6876133778400499707779c.png)  
Make sure, you changed your "environment " variable like this.  
Note: don’t need anything to change in the packege.json file .

---

<div class="post-metadata">

**Author:** ![jkbaseer](http://community.tradly.app/user_avatar/community.tradly.app/jkbaseer/32/1296_2.png) [@jkbaseer](http://community.tradly.app/u/jkbaseer)\
**Post date:** [15 February 2022 05:14 UTC](http://community.tradly.app/t/im-trying-to-run-starter-locally-and-i-get-401-unauthorized-invalid-api-key/161/12 "2022-02-15T05:14:20Z")

</div>

Hi @ccc if this still doesn’t works for you, let’s arrange a call for you, so we can troubleshoot together and understand why it doesn’t work for you
