Page 1 of 1

Odd request url formatting when passing localStorage value through JS (causes 'Incorrect query' error)

Posted: Fri Apr 04, 2014 8:36 pm
by Case

Hey guys, so I've read through the following posts hoping they would help but they just tell me how to do what I'm doing, not why I'm getting the bad/truncated request url encoding I'm seeing:

https://getsatisfaction.com/apperyio/...
https://getsatisfaction.com/apperyio/...
https://getsatisfaction.com/apperyio/...

On to my Issue:
I have a db list service and have added a "where" request parameter so I can filter my results to only show the rows owned by a specific user (pointed to in db).

Both the Test tab and a live run of the service works perfectly if I enter the complete 'where' query string into the request field, below is the query I'm adding to 'where':

{"owner": {"collName":"users", "id":"533f001ae4b013c661e5b884"}}
In Chrome Dev tools I see this succesful request header when run:
https://api.appery.io/rest/1/db/colle...

But of course I need to pull the correct/current userID from localStorage so I only display their records. I add the following JS to do so:
code
var currentUser = localStorage.getItem('user_id');
return {"owner": {"collName":"users", "id": currentUser}};
/code
This is where I get my "Incorrect query" error and see the request header has been sent as:
https://api.appery.io/rest/1/db/colle...

I've also tried draggin my local storage value over with a connection and adding JS referencing it as value, same issue.

I've done this for other types of queries, not sure why this isn't working but its had me troubleshooting for hours now.


Odd request url formatting when passing localStorage value through JS (causes 'Incorrect query' error)

Posted: Fri Apr 04, 2014 8:39 pm
by Case

I also tried:
code
var currentUser = localStorage.getItem('user_id');
return {"owner": {"collName":"users", "id":"' + currentUser + '"}};
/code
Since it seemed at one point maybe the issue was with quotes, am I formatting this incorrectly or is my syntax wrong?


Odd request url formatting when passing localStorage value through JS (causes 'Incorrect query' error)

Posted: Fri Apr 04, 2014 8:58 pm
by Maryna Brodina

Hello!

Please try prevar currentUser = localStorage.getItem('user_id');
return '{"owner": {"collName":"users", "id": "' + currentUser + '"}}';/pre


Odd request url formatting when passing localStorage value through JS (causes 'Incorrect query' error)

Posted: Fri Apr 04, 2014 9:06 pm
by Case

Works perfectly!
Gosh I love you guys, I knew it was something simple like this I was botching. Thanks!