egonzalez
Posts: 0
Joined: Fri Sep 14, 2012 9:34 pm

GET results using 2 Local Storage values into a single constraint ParseDB

Hi,
I'm using ParseDb and I'm trying to pass in 1 constraint consisting of 2 local storage values. I've used 1 local storage value in the past without any issues. I would typically substitute the objectID value for "'+value+'" which always works well. I realize that mapping 2 local storage values to the query will not work this way. How should I identify each local storage value?
This is the query I am working with:

{"teacher":{"type":"Pointer","className":"_User","objectId":"MSSmmyU1BX"},"granted":false,"event": { "type": "Pointer", "className": "Event", "objectId": "nfQCCBMGkl" }}

Thanks
Eric

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

GET results using 2 Local Storage values into a single constraint ParseDB

In JavaScript mapping for the paramater, use the local storage API directly:

code
var value1 = localStorage.getItem("value1");

var value2 = localStorage.getItem("value2");
/code

then create the string you need to return.

egonzalez
Posts: 0
Joined: Fri Sep 14, 2012 9:34 pm

GET results using 2 Local Storage values into a single constraint ParseDB

I'm adding this to the javascript for the request mapping but it's not working. What am I missing?

var event = localStorage.getItem("eventIdLS");
var user = localStorage.getItem("userIdLS");
return '{"teacher":{"type":"Pointer","className":"_User","objectId":user},"granted":false,"event": { "type": "Pointer", "className": "Event", "objectId":event}}';

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

GET results using 2 Local Storage values into a single constraint ParseDB

Hello! Could you clarify what exactly doesn't work? Maybe this can help https://www.parse.com/docs/rest#queries

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

GET results using 2 Local Storage values into a single constraint ParseDB

Before you add the values from local storage, make sure the return works as a plain string.

egonzalez
Posts: 0
Joined: Fri Sep 14, 2012 9:34 pm

GET results using 2 Local Storage values into a single constraint ParseDB

When I test the return in the Services (Test Connection) section , it works perfectly. Is that what you are talking about?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

GET results using 2 Local Storage values into a single constraint ParseDB

That's good. Next you should test it from the page, in mapping. But don't insert the values from local storage yet, hard code them into the return string.

egonzalez
Posts: 0
Joined: Fri Sep 14, 2012 9:34 pm

GET results using 2 Local Storage values into a single constraint ParseDB

It works hardcoded on the page. =) I must be doing something wrong with the syntax.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

GET results using 2 Local Storage values into a single constraint ParseDB

Use console.log(..) on the string you create..use it in Test Connection.

egonzalez
Posts: 0
Joined: Fri Sep 14, 2012 9:34 pm

GET results using 2 Local Storage values into a single constraint ParseDB

This is what I am using.
var event = localStorage.getItem("eventIdLS");
var user = localStorage.getItem("userIdLS");
return '{"teacher":{"type":"Pointer","className":"_User","objectId":user},"granted":false,"event": { "type": "Pointer", "className": "Event", "objectId":event}}';
console.log(value);

and this is what I get in the console:

OPTIONS https://api.parse.com/1/classes/EPS?w... 200 (OK)

GET https://api.parse.com/1/classes/EPS?w... 400 (Bad Request)

Return to “Issues”