2

I am trying to use the Parse REST API to send push notifications but whenever I try and make an AJAX call, I get back an invalid JSON error in the response and a 400 status code. Here is my request

$.ajax({
  url: 'https://api.parse.com/1/push',
  headers: {
    "X-Parse-Application-Id": "apID",
    "X-Parse-REST-API-Key": "restKey",
    "Content-Type": "application/json"
  },
  data: {
    "where": {
      "appName": "CampMo"
    },
    "data": {
      "alert": "Test notification"
    }
  },
  error: function(e) {
    console.log(e);
  },
  success: function(data) {
    alert("success!");
  },
  type: 'POST'
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

The request works fine when I do it with a client like Postman but not when I am trying to do it through my web app. Is there something I am missing?

1 Answer 1

1

Pass your data as JSON stringified data

$.ajax({
  url: 'https://api.parse.com/1/push',
  headers: {
    "X-Parse-Application-Id": "apID",
    "X-Parse-REST-API-Key": "restKey",
    "Content-Type": "application/json"
  },
  data: '{"where": {"appName": "CampMo"},"data":{"alert":"Test notification" }}',
  error: function(e) {
    console.log(e);
  },
  success: function(data) {
    alert("success!");
  },
  type: 'POST'
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Sign up to request clarification or add additional context in comments.

2 Comments

Wow that worked! Why did the way you formatted the JSON like that make a difference?
you are defined header "Content-Type": "application/json"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.