title: How to POST API key to API gateway as a request header using Jquery AJAX
body: <p>I need to post json data to AWS API gateway which is protected by an API key. When I tried adding x-api-key header in Postman and made the request, the POST worked. However, I want to do the same thing with Jquery code. How do I add this x-api-key header in JQuery. Here is my code,</p>
  
  <pre><code>var myJSON = JSON.stringify(obj);
  
      $.ajax({
         type: "POST",
         url:  "&lt;aws-url&gt;" ,
         data: myJSON,
         crossDomain : true,
         dataType: 'json',
         beforeSend: function(xhr){xhr.setRequestHeader("X-Api-Key","&lt;value&gt;");},
         headers :{
                  'Content-Type':'application/x-www-form-urlencoded',
                  //'Authorization':'&lt;value&gt;'
                  },
         success: function(result) {
              console.log("ho gaya");
         }
      });
  </code></pre>
  
  <p>As you can see, I have tried adding "Authorization", "auth-key","AUTH-KEY", "X-Api-Key", "x-api-key" in the header section. I also added the header in the beforeSend section which again didn't work. Please help.</p>