Page 1 of 1

Querying Devices

Posted: Sat Apr 04, 2015 11:03 pm
by Joe Bohen

Hi, How do you query Devices from server script, the collection type with a App-ID rather than a database ID?

curl -X GET \
-H "Content-Type: application/json" \
-H "X-Appery-App-Id: c8e07429-c150-47788182-19937q8-90" \
https://api.appery.io/rest/push/reg/


Querying Devices

Posted: Sun Apr 05, 2015 8:55 pm
by Illya Stepanov

Hi Joe -

The devices are stored in the predefined collection in the database, so I think query just with header app ID won't work in this case.


Querying Devices

Posted: Mon Apr 06, 2015 11:15 am
by Joe Bohen

Thanks for the reply but what is the method used to get the data from the pre-defined collection?


Querying Devices

Posted: Tue Apr 07, 2015 12:31 am
by Yurii Orishchuk

Hi Joe,

Here is JS code for server code to get devices from built-in Devices collection.

precode

var DB_id = "52fd3d06xxxx11c89917&quot

var collectionName = "_devices&quot

try {
result = {};

//Using master key
var token = "2ff60f38-e6ac-4xxxxxxx9-a0c6-2f8282eac042&quot

var params = {};
params.criteria = {};

//Define other parameters
//params.skip = 3; //Skip first 3 records.
//params.limit = 6; //Show maximum 6 records
//params.sort = "studentId&quot //Ascending sort by field "studentId"
result.query = Collection.query(DB_id, collectionName, params, token); //Make the query and save it to the result object

response.success(result);
} catch (e) {
response.success("message: " + e.message + "ncode: " + e.code);
}

/code/pre

Also: don't forget to change settings(DBID and maseter key) with yours.

Regards.


Querying Devices

Posted: Tue Apr 07, 2015 3:20 am
by Joe Bohen

Hi Yurii, Thanks very much for the code it works perfectly.