title: Parse REST API 401 Unauthorized with JQuery Ajax
body: <p>I've been battling parse.com's REST API for an hour with no success. I keep getting HTTP 401 with response <code>{"error": "unauthorized"}</code>. </p>
  
  <p>Here is my cloud code:</p>
  
  <pre><code>Parse.Cloud.define("sendEmail", function(request, response) {
  
    var Mailgun = require('mailgun');
    Mailgun.initialize('mg.crawford.works', 'key-c67f7a53cf12b2aabeaade0e50d57e8f');
  
    Mailgun.sendEmail
    ({
      "to": "sales@crawford.works",
      "from": "website@crawford.works",
      "subject": "Website Form Submission",
      "text": "Name: " + request.params.name + "\nEmail:  "+request.params.email+"\nPhone: "+request.params.phone+"\nMessage: "+request.params.msg
    }, 
    {
      success: function(httpResponse) 
      {
        console.log(httpResponse);
        response.success("success");
      },
      error: function(httpResponse) 
      {
        console.error(httpResponse);
        response.error("error");
      }
    });
  });
  </code></pre>
  
  <p>Here is my client side code (just for form submission):</p>
  
  <pre><code>var data = {};
  
  data.name = $("#name").val();
  
  data.email = $("#email").val();
  
  data.msg = $("#message").val();
  
  data.phone = $("#phone").val();
  $.ajax({
    method: 'post',
    url: "http://api.parse.com/1/functions/sendEmail",
    data: JSON.stringify(data),
    contentType: 'application/json',
    headers: 
    { 
      'X-Parse-Application-Id': 'This is the right key, triple checked',
      'X-Parse-REST-API-Key': 'Same story here'
    }
  })
  .done(function (response) {
    if (response.success == 'success') {               
      alert('success');                       
    } else {
      alert('fail');
    }
  });
  return false; // required to block normal submit since you used ajax
  </code></pre>
  
  <p>I've looked at many parse support fourms like this one (StackOverFlow isn't letting me put more links b/c I'm still noob): <a href="https://www.parse.com/questions/401-unauthorized-error-with-parse-rest-api" rel="nofollow">https://www.parse.com/questions/401-unauthorized-error-with-parse-rest-api</a></p>
  
  <p>Appreciate any help you can give,</p>
  
  <p>@acrawly</p>