Page 1 of 2

(undocumented) database REST error code: 'DBSP007', description: 'Serialization error'

Posted: Tue Aug 12, 2014 4:39 am
by axkrishnan

Hello,

I'm running the following server code to update existing rows of a table. My understanding is that the correct way to do this is to issue a PUT to the rest interface with two query strings: "where" and "operations". When I do a GET with just the "where" clause, everything works the way I would expect it to, but when I add an "operations" clause to update rows matching the "where" query I always get the error shown in the title.

I have created this test case which boils down to where the problem lies. I have created a database with a single collection called "table" that should be open to the public, so the following sample code should work. The schema/rows of the collection can be seen in the attached screenshot.

The code:

var responseBody = {},
requestParams = {},
paramKeys = request.keys();

for (var key = 0; key < paramKeys.length; key++) {
requestParams[paramKeys[key]] = request.get(paramKeys[key]);
}
// Declare database ID
var dbId = "53e996efe4b0e68a8dbfbc3a";

try {

var XHRResponse = XHR.send("PUT", "https://api.appery.io/rest/1/db/colle...", {
"headers": {
"X-Appery-Database-Id": dbId,
"Content-Type":"application/json"
},
"parameters": {
"operations" : '{"$set":{"toggle":true}}',
"where": '{"name":"one"}'
}
});

if (XHRResponse.status != 200) {
responseBody.message = "message: " + XHRResponse.body + "\ncode: " + XHRResponse.status;
console.log(XHRResponse.body);
response.error(responseBody, "application/json");
} else {
console.log("Success: " + JSON.stringify(XHRResponse.body[0]));
response.success();
}

Am I missing something obvious? The error code that I'm getting doesn't seem to be documented anywhere and all the posts in this forum with the same error code seem to be completely unrelated to my problem.

I have to use the REST API to the DB instead of the nicer javascript hooks because in my application the task I am doing requires the master key. FYI this script can be called via rest at: https://api.appery.io/rest/1/code/0a1...

Image


(undocumented) database REST error code: 'DBSP007', description: 'Serialization error'

Posted: Tue Aug 12, 2014 9:07 am
by Evgene Karachevtsev

Hello,

Please look at the documentation for the server code, the method multiUpdateObject here:
http://devcenter.appery.io/documentat...


(undocumented) database REST error code: 'DBSP007', description: 'Serialization error'

Posted: Tue Aug 12, 2014 3:15 pm
by Kal

Evgene, as the OP stated, this method cannot be used when a Master Key is needed to be used for the update process. The Master Key mechanism seems to be available only via REST interface, not through the DB API, unless I am missing something.


(undocumented) database REST error code: 'DBSP007', description: 'Serialization error'

Posted: Tue Aug 12, 2014 6:41 pm
by axkrishnan

As Kal stated, unfortunately the multiUpdateObject function is not an option for me. Also I just re-read my post and it looks like the copy-paste of the code got cut short. Since I don't see a way to edit my first post, I will re-paste the code I am using here:

pre
var responseBody = {},
requestParams = {},
paramKeys = request&#46;keys();

for (var key = 0; key < paramKeys&#46;length; key++) {
requestParams[paramKeys[key]] = request&#46;get(paramKeys[key]);
}
&#47;&#47; Declare database ID
var dbId = "53e996efe4b0e68a8dbfbc3a";

try {

var XHRResponse = XHR&#46;send("PUT", "https:&#47;&#47;api&#46;appery&#46;io/rest/1/db/collections/table", {
"headers": {
"X-Appery-Database-Id": dbId,
"Content-Type":"application/json"
},
"parameters": {
"operations" : '{"$set":{"toggle":true}}',
"where": '{"name":"one"}'
}
});

if (XHRResponse&#46;status != 200) {
responseBody&#46;message = "message: " + XHRResponse&#46;body + "\ncode: " + XHRResponse&#46;status;
console&#46;log(XHRResponse&#46;body);
response&#46;error(responseBody, "application/json");
} else {
console&#46;log("Success: " + JSON&#46;stringify(XHRResponse&#46;body[0]));
response&#46;success();
}
} catch (e) {
responseBody&#46;message = "JAVASCRIPT EXCEPTION message: " + e&#46;message + "code: " + e&#46;code;
console&#46;log(e);
response&#46;error(responseBody, "application/json");
}
/pre


(undocumented) database REST error code: 'DBSP007', description: 'Serialization error'

Posted: Tue Aug 12, 2014 7:02 pm
by Kal

Just FYI, I use the same kind of thing on the client side (with where clause and operations.$set clause), and it works fine via REST API. Only from the server side JS, do I get this error.


(undocumented) database REST error code: 'DBSP007', description: 'Serialization error'

Posted: Tue Aug 12, 2014 10:23 pm
by Yurii Orishchuk

Hi all,

Please use following code:

pre

var responseBody = {},
requestParams = {},
paramKeys = request&#46;keys();

for (var key = 0; key < paramKeys&#46;length; key++) {
requestParams[paramKeys[key]] = request&#46;get(paramKeys[key]);
}
&#47;&#47; Declare database ID
var dbId = "52faaaa6e4b0a25c11c89917";

&#47;&#47;Here is your request object&#46;
var bodyObject = {
"operations": '{"$set":{"toggle":true}}',
"where": '{"name":"one"}'
};

&#47;&#47;Note here you should replace URL with yours&#46;
var XHRResponse = XHR&#46;send("PUT", "https:&#47;&#47;api&#46;appery&#46;io/rest/1/db/collections/dogs/53baaaaae4b09f5c7d50390f", {
"headers": {
"X-Appery-Database-Id": dbId,
"Content-Type": "application/json"
},

"body": JSON&#46;stringify(bodyObject)

});

if (XHRResponse&#46;status != 200) {
responseBody&#46;message = "message: " + XHRResponse&#46;body + "\ncode: " + XHRResponse&#46;status;
console&#46;log(XHRResponse&#46;body);
response&#46;error(responseBody, "application/json");
} else {
console&#46;log("Success: " + JSON&#46;stringify(XHRResponse&#46;body[0]));
response&#46;success();
}

/pre

Regards


(undocumented) database REST error code: 'DBSP007', description: 'Serialization error'

Posted: Tue Aug 12, 2014 11:27 pm
by axkrishnan

Ah, that's a good idea sending the query as part of the body. Unfortunately I am still getting the exact same error. (I modified your code so that the url pointed to my test table and the database ID is that of my test case's db.)

I notice that your URL specifies an object in your table. Is that just an artifact from code you pulled from elsewhere? Because it doesn't make sense to me that you would need to specify an object ID when running a query that may match multiple rows.

Also on a side note, using curl and passing the "operations" and "where" as query strings results in the same error. The curl that I attempted was:
precurl -X PUT -H "X-Appery-Database-Id: 53e996efe4b0e68a8dbfbc3a" -H "Content-Type: application/json" -G --data-urlencode 'operations={"$set":{"toggle":true}}' -G --data-urlencode 'where={"name":"one"}' https:&#47;&#47;api&#46;appery&#46;io/rest/1/db/collections/table/pre
The response was the same error. This leads me to believe that the issue may not be javascript related at all, but simply an error in my "operations" string. However I can't for the life of me find any problem with it.

Thanks for the idea, but this issue is still not resolved.


(undocumented) database REST error code: 'DBSP007', description: 'Serialization error'

Posted: Wed Aug 13, 2014 2:19 am
by Yurii Orishchuk

Dear axkrishnan,

You can not modify several items per single request.

Every "put" request should have "_id" value in the URL. As shown in my code above.

Please take a look about update REST DB API here: http://devcenter.appery.io/documentat...

So for your purpose you need to iterate this request several times for each item that's you need to update.

I've changed given code to be more clear:

pre

var responseBody = {},
requestParams = {},
paramKeys = request&#46;keys();

for (var key = 0; key < paramKeys&#46;length; key++) {
requestParams[paramKeys[key]] = request&#46;get(paramKeys[key]);
}

&#47;&#47;Settings:
var dbId = "52fd3d06e4b0a25c11c89917";
var collectionName = "dogs";
var itemId = "53ba2599e4b09f5c7d50390f";

&#47;&#47;Note: "operations" and "where" is not a commands but collection fields&#46;
&#47;&#47;So with this body you will upate "operations" field with value "{"$set":{"toggle":true}}" and update "where" with value '{"name":"one"}'&#46;
var bodyObject = {
"operations": '{"$set":{"toggle":true}}',
"where": '{"name":"one"}'
};

var XHRResponse = XHR&#46;send("PUT", "https:&#47;&#47;api&#46;appery&#46;io/rest/1/db/collections/" + collectionName + "/" + itemId + "", {
"headers": {
"X-Appery-Database-Id": dbId,
"Content-Type": "application/json"
},

"body": JSON&#46;stringify(bodyObject)

});

if (XHRResponse&#46;status != 200) {
responseBody&#46;message = "message: " + XHRResponse&#46;body + "\ncode: " + XHRResponse&#46;status;
console&#46;log(XHRResponse&#46;body);
response&#46;error(responseBody, "application/json");
} else {
console&#46;log("Success: " + JSON&#46;stringify(XHRResponse&#46;body[0]));
response&#46;success();
}

/pre

Regards.


(undocumented) database REST error code: 'DBSP007', description: 'Serialization error'

Posted: Wed Aug 13, 2014 2:27 am
by Kal

Yurii, something doesn't make sense here. If I already have the ID of the row I want to change, what is the point of the "where" clause?


(undocumented) database REST error code: 'DBSP007', description: 'Serialization error'

Posted: Wed Aug 13, 2014 2:56 am
by Yurii Orishchuk

Hi Kal,

Did you read code comments?

Please take a look: http://prntscr.com/4ca6j4/direct

Also "where" clause does not supports in "update" service.

So you can pass it to the request but this parameter will accepted as field that's you want to update. So you can have in your collection "where" field and this field will be updated with passed value. Does it make sense?

Also, where did you get information about "where" clause in update service?

Regards.