Rohan Deshpande
Rohan Deshpande

Reputation: 694

Cannot update Parse object via REST API

Right, so I'm simply trying to update my object via the REST API. My request succeeds, I get a 200 response back containing the latest updated timestamp, but the object's column value has not changed.

My Movies class has a title and a genre column, the rights on the class are set to public read write on all rows.

Here is some code

var data = {title:'The Revenant'};

qwest.put('https://api.parse.com/1/classes/Movies/myObjectId', JSON.stringify(data))
    .then(function(xhr, response) {
        console.log(response);
    })
    .catch(function(xhr, response, e) {
        console.log(e);
    });

The response I get back?

{"updatedAt":"2016-01-24T07:59:54.977Z"}

So the request succeeded but if I GET the object again or check in the Parse admin page, the object has not changed. What gives?

EDIT

FYI, if I use the Javascript SDK, I can update the model.

var Movies = Parse.Object.extend("Movies");
var query = new Parse.Query(Movies);

query.get(myObjectId, {
    success: function (movie) {
        movie.set("title", data.title);
        movie.save();
    },
    error: function (object, error) {
        console.log(error);
    }
});

This updates the model. For my particular use case though, I would really prefer to use the REST API rather than the SDK, but I guess this means it is not a permissions issue or an id mismatch etc.,

Upvotes: 4

Views: 599

Answers (3)

juancevi
juancevi

Reputation: 376

code snippet

qwest.put('https://api.parse.com/1/classes/Movies/Dh7zjiP9KW', data,    {dataType:"json",headers:{'x-parse-application-id':'XXX','X-Parse-REST-    API-Key':'XXX'}})
            .then(function(xhr, response) {
                console.log(response);
            })
            .catch(function(xhr, response, e) {
                console.log(e);
            });

Upvotes: 3

juancevi
juancevi

Reputation: 376

Try removing JSON.stringify(data) and just pass data,

Upvotes: 0

Héctor Ramos
Héctor Ramos

Reputation: 9258

The response you're getting indicates that the object was updated successfully. Double check that you're looking at the correct object, and that the "updatedAt" field matches the response you saw earlier.

What happens if you fetch the object right away, using the same "qwest" client and https://api.parse.com/1/classes/Movies/myObjectId resource URL (with the correct object id)?

Upvotes: 0

Related Questions