Page 1 of 1

Server code query to users database returns 200 whether records exist or not

Posted: Tue Apr 01, 2014 9:30 pm
by Mark Bowen6778362

I have a server code will create an email invitation if a user does not exist. My code works perfectly and I have removed the - thanks to the great tutorials and guidance here with one exception. I am testing with a valid token, database id and masterkey

Even if the user does not exist the XHRResponse.status is 200 (and therefore the next step generates an uncaught error)

What have I done wrong?

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

for (var key = 0; key < paramKeys.length; key++) {
requestParams[paramKeys[key]] = request.get(paramKeys[key]);
}
var dbId = "";
var masterKey = "";
var tokenId = requestParams["tokenId"];
var email = requestParams["emailInvite"];

var XHRResponse = XHR.send("GET", "https://api.appery.io/rest/1/db/users", { // return the userid for the given user
"headers": {
"X-Appery-Database-Id": dbId,
"X-Appery-Master-Key": masterKey
},
"parameters": {
"where": '{"username":"' + email + '"}'}

});
if (XHRResponse.status === 200) {
do everything else and send email from server
}


Server code query to users database returns 200 whether records exist or not

Posted: Wed Apr 02, 2014 3:21 am
by Igor

Hello,

You should specify dbid and masterKey. It's mandatory parameters.


Server code query to users database returns 200 whether records exist or not

Posted: Wed Apr 02, 2014 6:28 am
by Mark Bowen6778362

Yes these are defined, I just chose not to share them on a public forum

As I say my problem is why the database is returning 200 whether the address contained within 'email' exists or not


Server code query to users database returns 200 whether records exist or not

Posted: Wed Apr 02, 2014 2:18 pm
by Kateryna Grynko

Hi Mark,

If there is no such record in database then this is not an error, just an empty response:
http://docs.appery.io/documentation/b...


Server code query to users database returns 200 whether records exist or not

Posted: Wed Apr 02, 2014 7:21 pm
by Mark Bowen6778362

I have changed to XHRResponse.body.length to check whether a record exists and it works. Thanks you for your help - again