Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'POST 400 bad request' error when updating parse.com table

I am getting a 'POST 400 bad request' error when trying to update a table on parse.com using JS SDK.

var Gallery = Parse.Object.extend("Gallery");
var gallery = new Gallery();
var activeArtworks = 0;
gallery.save(null, {
    success: function(gallery) {
          gallery.set("activeArtworks", activeArtworks);
          gallery.save();
    }
});

Please help!

I can't see how this is any different to the sample code provided by parse here

like image 975
vedran Avatar asked Oct 28 '12 09:10

vedran


People also ask

What is the reason for 400 Bad Request?

The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing).

When can I return a Bad Request?

400 Bad Request: The request cannot be fulfilled due to bad syntax. In this case, your client sent you an XML payload that had an invalid zip code, which is a form of invalid syntax; therefore, sending a 400 Bad Request is an appropriate error code to return in this situation.


1 Answers

The sample code you reference creates all of its parameters before setting up the save() method. This is the step you're missing; you need to create the activeArtworks parameter on your gallery instance. Your update is failing because you're trying to update a property that was never created.

I would expect this code to work, though I didn't test it because parse.com requires you to set up an account to run any code, which is silly, and I didn't feel like creating one:

var Gallery = Parse.Object.extend("Gallery");
var gallery = new Gallery();
var activeArtworks = 0;
gallery.activeArtworks = []; // or some more appropriate default if you have one.
gallery.save(null, {
    success: function(gallery) {
        gallery.set("activeArtworks", activeArtworks);
        gallery.save();
    }
});

It might also be worth checking if there's any info in the headers of the 400 error (the debug console in your browser will show these in its Network tab). I would expect Parse to give you some sort of information to help you debug issues, and that's the only place it would fit for an HTTP error.

like image 155
Dan M Avatar answered Sep 24 '22 13:09

Dan M