Node Parse API
install
npm install node-parse-api
examples
setup with MASTER_KEY
var Parse = require('node-parse-api').Parse;
var APP_ID = ...;
var MASTER_KEY = ...;
var app = new Parse(APP_ID, MASTER_KEY);
setup with API_KEY
var Parse = require('node-parse-api').Parse;
var options = {
app_id:'...',
api_key:'...'
}
var app = new Parse(options);
insert an object
- insert(className
string
, data object
, callback function
)
app.insert('Foo', { foo: 'bar' }, function (err, response) {
console.log(response);
});
insert a User
- insertUser(data
object
, callback function
)
app.insertUser({
username: 'foo',
password: 'bar'
}, function (err, response) {
console.log(response);
});
More properties can be provided, but username and password are required.
insert a User with a Pointer
app.insertUser({
username: 'foo',
password: 'bar',
pointer: {
__type: 'Pointer',
className: <string>,
objectId: <string>
}
}, function (err, response) {
console.log(response);
});
insert a User with GeoPoints
app.insertUser({
username: 'foo',
password: 'bar',
location: {
__type: 'GeoPoint',
latitude: <int>,
longitude: <int>
}
}, function (err, response) {
console.log(response);
});
user login
- loginUser(username
string
, password string
, callback function
)
Response contains all of the user fields except password, also includes a sessionToken for this user.
app.loginUser('foo', 'bar', function (error, response) {
});
me
- me(sessionToken
string
, callback function
)
app.me('sessionToken', function (error, response) {
});
insert a file
- insertFile(fileName
string
, data string/buffer
, contentType string
, callback function
)
app.insertFile('foo.txt', 'bar', 'text/plain', function (err, response) {
app.insert('MyFile', {__type: 'File', "name": response.name }, function (error, response) {
});
});
find one
- find(className
string
, query object
, callback function
)
app.find('Foo', {objectId: 'someId'}, function (err, response) {
console.log(response);
});
Returned fields can be restricted with the 'keys' query.
var query = {
objectId: 'someId',
keys: 'foo,bar'
};
app.find('Foo', query, function (error, response) {
});
find many
- find(className
string
, query object
, callback function
)
app.find('Foo', {where: {foo: 'bar'}}, function (err, response) {
console.log(response);
});
app.find('Foo', '', function (err, response) {
console.log(response);
}):
All types of query constraints Parse provides can be added to the query object as properties. (order, limit, keys, count, include...)
var query = {
where: {
foo: 'bar',
baz: 'qux'
},
limit: 10,
skip: 5,
order: '-createdAt'
};
app.find('Foo', query, function (error, response ) {
});
find one user
- getUser(query
object
, callback function
)
app.find({objectId: 'someId'}, function (err, response) {
console.log(response);
});
find many users
- getUser(query
object
, callback function
)
app.find({where: {foo: 'bar'}}, function (err, response) {
console.log(response);
});
app.find('', function (err, response) {
console.log(response);
}):
count the number of objects
var query = {
count: 1,
limit: 0
};
app.find('Foo', query, function (error, response) {
});
edit an object
- update(className
string
, objectId string
, callback function
)
app.update('Foo', 'someId', {foo: 'bar'}, function (err, response) {
console.log(response);
});
delete an object
- delete(className
string
, objectId string
, callback function
)
app.delete('Foo', 'someId', function (err, response) {
});
delete all objects in a class
- deleteAll(className
string
, callback function
)
app.deleteAll('Foo', function (err, response) {
});
delete user
- deleteUser(objectId
string
, [sessionToken string
], callback function
)
If you are using the master key you don't need any session tokens.
app.deleteUser('someId', function (err, response) {
});
If you're using the rest api key you will need a session token and will only be able to delete the user object of the matching user.
app.deleteUser('someId', 'sessionToken', function (error, response) {
});
delete all users
- deleteAllUsers(callback
function
)
This will only work when using the master key.
app.deleteAllUsers(function (err, response) {
});
reset a password
- passwordReset(data
string
, callback function
)
app.passwordReset(email, function(err, response){
console.log(response);
});
edit a user object
- updateUser(objectId
string
, data object
, [sessionToken string
], callback function
)
With master key
app.updateUser('someId', {email: 'foo@example.com'}, function(err, response){
console.log(response);
});
or with rest api key
app.updateUser('someId', {email: 'foo@example.com'}, 'sesstionToken', function(err, response){
console.log(response);
});
batch requests
- batch(requests
array
, callback function
)
var requests = [
{
method: 'POST',
path: '/1/classes/Foo',
body: {
foo: 'bar1',
baz: 'qux1'
}
},
{
method: 'POST',
path: '/1/classes/Foo',
body: {
foo: 'bar2',
baz: 'qux2'
}
}
];
app.batch(requests, function (error, response) {
});
insert installation data
app.insertInstallationData("ios", "0123456784abcdef0123456789abcdef0123456789abcdef0123456789abcdef", function(err, response){
if (err) {
console.log(err);
} else {
console.log(response);
}
});
insert installation data with timeZone
app.insertInstallationDataWithTimeZone("ios", "0123456784abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "EST", function(err, response){
if (err) {
console.log(err);
} else {
console.log(response);
}
});
insert installation data with channels
arr = ["news", "sports"];
app.insertInstallationDataWithChannels("ios", "0123456784abcdef0123456789abcdef0123456789abcdef0123456789abcdef", arr, function(err, response){
if (err) {
console.log(err);
} else {
console.log(response);
}
});
insert installation data with timeZone and channels
arr = ["news", "sports"];
app.insertInstallationDataWithTimeZoneAndChannels("ios", "0123456784abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "EST", arr, function(err, response){
if (err) {
console.log(err);
} else {
console.log(response);
}
});
create a role for a particular user
var data = {
name: 'Administrator',
ACL: {
"*": {
"read": true
}
},
roles: {
"__op": "AddRelation",
"objects": [
{
"__type": "Pointer",
"className": "_Role",
"objectId": "<objectId>"
}
]
},
users: {
"__op": "AddRelation",
"objects": [
{
"__type": "Pointer",
"className": "_User",
"objectId": "<objectId>"
}
]
}
};
app.insertRole(data, function(err, resp){
console.log(resp);
});
get a role
app.getRole("<objectId>", function(err, resp){
console.log(resp);
});
update a role
var data = {
users: {
"__op": "RemoveRelation",
"objects": [
{
"__type": "Pointer",
"className": "_User",
"objectId": "<objectId>"
}
]
}
};
app.updateRole("<objectId>", data, function(err, resp){
console.log(resp);
});
delete a role
app.deleteRole("<objectId>", function(err, resp){});
get all the roles
app.getRoles(function(err, resp){});
get a role against a cetain param
var params = {
where: { name: "Administrator" }
};
app.getRoles(params, function(err, resp){
console.log(resp);
});
send a push notification
var notification = {
channels: [''],
data: {
alert: "sending too many push notifications is obnoxious"
}
};
app.sendPush(notification, function(err, resp){
console.log(resp);
});
note on sending dates
{
"__type": "Date",
"iso": new Date("<year>", "<month>", "<day>").toJSON()
}
License
node-parse-api is available under the MIT license.
Copyright © 2015 Mike Leveton and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.