amplitude-js changing request-header doesn't work

  • 8 March 2022
  • 1 reply

I have a simple react application using amplitude-js to send payloads to our API. Our API controller accepts and parses json message (application/json;charset=utf-8) but amplitude-js sends data in format data.

I tried below code in my react application where I initiate amplitude intance but it doesn't work, it still sends the data in application/x-www-form-urlencoded format which is default:

const amplitudeInstance = amplitude.getInstance("test").init("21e0fe6c98573ae71d209cb8ec4e85eb", null, {
// optional configuration options
saveEvents: false,
headers: {
'Content-Type': 'application/json;charset=utf-8'

logEvent:'test data'

So my question is why can't I change amplitude-js's content-type as they mention in docs: (Configuring HTTP Headers)



Best answer by Denis Holmes 9 March 2022, 11:39

View original

1 reply

Userlevel 6
Badge +8

Hi @deolandscsaping 


Thanks for writing into chat! Glad to help.


So you are configuring the HTTP headers. Do you have a domain proxy? Or what is your reason for configuring them exactly? Usually customers would not do this unless they are using a proxy, is that the case? Domain proxy article here.


Have you tried to send the data without configuring the headers? It usually ingests fine for me and my system can ingest it with application/json;charset=utf-8. May I ask what is your entire goal here? Maybe then I can guide you in the right way!


I look forward to your reply!


Kind Regards,