Page 1 of 4

Using ?WHERE= in URL database call

Posted: Sun Dec 08, 2013 11:55 am
by Andrew Walker

I have an issue where I am trying to retrieve an object from the database to a website.

codevar s_name = $('#sourceName').text();
var s_id = $('#sourcePasscode').text();
$.ajax({
url: 'https://api.appery.io/rest/1/db/collections/source?where={"source_name":"'+s_name+'", "_id" : "'+s_id+'"}',

beforeSend: function(xhr) {
xhr.setRequestHeader("X-Appery-Database-Id", "529****************d");
},
success: function(data) {
console.log(data);
}
}); /code

There is something incorrect about the call, as I keep getting 400 errors about 'bad request'.

Any ideas on how to fix this ? Thanks


Using ?WHERE= in URL database call

Posted: Sun Dec 08, 2013 1:20 pm
by Illya Stepanov

Hi Andrew,

Can you post a screenshot of this entire error message?


Using ?WHERE= in URL database call

Posted: Sun Dec 08, 2013 1:22 pm
by Andrew Walker

Using ?WHERE= in URL database call

Posted: Sun Dec 08, 2013 4:06 pm
by Andrew Walker

I have tried many ways of doing it, but still get the 'Invalid HTTP 400' error :(

code
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Appery-Database-Id", "529e2609e4b04c118d013b9d");
xhr.setRequestHeader("Content-Type", "application/json");
},
type: 'GET',
url: 'https://api.appery.io/rest/1/db/collections/source?where={"source_name" : "'+s_name+'"}',
success: function(data) {
console.log(data);
}
});
/code


Using ?WHERE= in URL database call

Posted: Sun Dec 08, 2013 4:15 pm
by Illya Stepanov

Sorry we still working on this issue without any news.


Using ?WHERE= in URL database call

Posted: Sun Dec 08, 2013 4:18 pm
by Andrew Walker

Okay, thank you, thought you had forgotten about me :)


Using ?WHERE= in URL database call

Posted: Sun Dec 08, 2013 6:32 pm
by Igor

Hello,

Please try to use simple request first:
pre
$.ajax({
type: "GET",
headers: {
'X-Appery-Database-ID': '5166b6a8e4b055aafd1f2167'
},
url:'https://api.appery.io/rest/1/db/collections/todo',
processData: false,
dataType: "json",
success: function (data) {
console.log("Successfully loaded");
},
error: function (xhr) {
console.log("Load error: " + xhr.status + " " + xhr.responseText);
}
});
/pre

if it works then you can add where cause parameter:
http://docs.appery.io/documentation/b...

Also next link should be helpful:
https://getsatisfaction.com/apperyio/...
https://gist.github.com/anonymous/29a...


Using ?WHERE= in URL database call

Posted: Sun Dec 08, 2013 6:47 pm
by Andrew Walker

Simple calls work fine, I can bring Collections over and work with them. The problem is when I put the WHERE= .....

This is where I get the error 400 HTTP invalid. So the statement must be wrong, so i am looking for the correct syntax ?


Using ?WHERE= in URL database call

Posted: Sun Dec 08, 2013 7:03 pm
by Andrew Walker

Either the syntax is incorrect in the URL, or I am doing something incorrect in the decoding of the JSON.

codeurl: 'https://api.appery.io/rest/1/db/collections/source?where={source_name="'+s_name+'"}'/code

From your documentation, which you first linked on your post, the above should work?


Using ?WHERE= in URL database call

Posted: Sun Dec 08, 2013 7:15 pm
by Andrew Walker

Okay, I have changed my URL to this:

codehttps://api.appery.io/rest/1/db/collections/source/where={"source_name" : "testCouncil"}/code

And now I get this error, which means much more to me

Load error: 400 {"code":"DBSG210","description":"Invalid object ID: 'where={\"source_name\"" : \""testCouncil\""}'""}"