Mark Bowen6778362
Posts: 0
Joined: Tue Apr 01, 2014 9:30 pm

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

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
}

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

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

Hello,

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

Mark Bowen6778362
Posts: 0
Joined: Tue Apr 01, 2014 9:30 pm

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

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

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...

Mark Bowen6778362
Posts: 0
Joined: Tue Apr 01, 2014 9:30 pm

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

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

Return to “Issues”