title: Hide an API key from the client side
body: <p>I am attempting an API integration with Zendesk. I'm having a lot of problems. You can see the questions I've asked about it so far below:</p>
  
  <p><a href="https://stackoverflow.com/questions/45448245/how-to-pass-an-access-token-in-an-ajax-call">How to pass an access token in an ajax call</a></p>
  
  <p><a href="https://stackoverflow.com/questions/45442344/zendesk-api-ticket-submission-using-javascript-authorization">ZenDesk API ticket submission using Javascript - authorization</a></p>
  
  <p>Now the good news - I have it working on the surface. however my API key is publicly in the client side Javascript, and I need to figure out someway to hide it. This is currently what my code looks like:</p>
  
  <pre><code>$.ajax({
          type: 'post',
          url: 'https://domain.zendesk.com/api/v2/tickets.json',
          data: {
            "ticket": {
              "subject": "new contact from " + contactEmail,
              "comment": {
                "body": contactFirstName + ' ' + contactLastName + ' ' + 'says: ' + contactMessage + contactEmail
              }
            }
          },
          beforeSend : function(xhr) {
              xhr.setRequestHeader( 'Authorization', 'BEARER (my key is here)' );
          },
          success: function(response) {
              console.log(response);
          },
          error : function(error) {
              console.log(error);
          }
          console.log('support ticket sent');
        });
  </code></pre>
  
  <p>My research has led me to the following resources:</p>
  
  <p><a href="https://stackoverflow.com/questions/38237673/how-to-hide-an-api-key-in-client-side-javascript">How to Hide an API Key in Client-Side Javascript</a></p>
  
  <p><a href="http://billpatrianakos.me/blog/2016/02/15/securing-api-keys-in-a-javascript-single-page-app/" rel="nofollow noreferrer">http://billpatrianakos.me/blog/2016/02/15/securing-api-keys-in-a-javascript-single-page-app/</a></p>
  
  <p><a href="https://stackoverflow.com/questions/32290889/using-js-php-js-to-hide-api-key">Using JS/PHP/JS to hide API key</a></p>
  
  <p>They all share the setiment that this should be handled on the server side. However, I cannot find any clear cut tutorials on how to do this. Can someone give me an idea on how to even start? Been stuck on this for over a week. </p>