Question

Invalid API key error: 400 Bad request

  • 11 December 2023
  • 3 replies
  • 83 views

Hi there,

I’m new to Amplitude.

I’m using the Browser SDK and getting the following error in the console only in production env (in local, dev env it works well):

“Amplitude Logger [Error]: Invalid API key”


This is my code

function InitAmplitude() {
if (environment.AMPLITUDE_API_KEY && environment.IS_AMPLITUDE_TRACKED) {
amplitude.init(environment.AMPLITUDE_API_KEY, {
serverZone: 'US',
defaultTracking: true,
});
}
}

I double, triple checked and the API key matches what I got from Amplitude’s settings. What am I doing wrong?


3 replies

Hello @Minseo Kim !
 

I have the same problem ! Did you manage to find a solution or a workaround ?

Cheers

Antoine

Hello !


I just found the problem.


The API key had an extra \r at the end because the end of line sequence was CRLF instead of LF in my .env file.

Hope it helps ! :)

Thanks for sharing these insights mate as I found this very informative.

Reply