Rest API allows you to perform actions such as queries and data update.
In order to connect via API you must receive the following parameters:
1.X-Parse-Application-Id – the database’s identifier. This parameter isn’t confidential.
2. X-Parse-Master-Key – the master password for your database. With its help, you have the highest permissions to the database. You must keep it unexposed to the users.
For the purpose of the exercise, we’ll create within the database a table named Accounts (in the case it doesn’t exist). In the table we will launch three fields –
1.Name – string
2.PhoneNumber – string
3.Score – Number
We will use an API simulator – https://apitester.com/
First example, turning to the Accounts table.
In the field ‘Request’ we’ll enter a general name for example.
We’ll choose ‘Post’ and enter the service address for Accounts – https://api.mbapps.co.il/parse/classes/Accounts
In the field ‘Post Data’ we’ll enter the following value:
{
"_method":"get"
}
In the Header we’ll add three values:
1.Content-Type: application/json
2.X-Parse-Application-Id: Your application ID
3.X-Parse-Master-Key: Your Master Key
Now, once we examine the service (clicking Test), we’ll receive a list of clients’ objects existing within the database.
At this point, we’ll change the content of ‘Post’ and add a condition/filter Accounts by the name equals to John:
{
“_method”:”get”,
“where”:{“Name”:”John”}
}
Let test it again.
The following is a list of usable operations:
Key Operation
$lt Less Than
$lte Less Than Or Equal To
$gt Greater Than
$gte Greater Than Or Equal To
$ne Not Equal To
$in Contained In
$nin Not Contained in
$exists A value is set for the key
$select This matches a value for a key in the result of a different query
$dontSelect Requires that a key’s value not match a value for a key in the result of a different query
$all Contains all of the given values
$regex Requires that a key’s value match a regular expression
$text Performs a full text search on indexed fields
Additional examples:
Retrieve accounts where Email is : test@mybusiness-crm.com.
{
"_method":"get",
"where":{"Email":"test@mybusiness-crm.com"}
}
Retrieve accounts where name like Jo.
{
"_method":"get",
"where":{"Name":{"$regex":"^Jo"}}
}
Retrieve accounts where name is John and Phone Number is like 054.
{
"_method":"get",
"where":{"PhoneNumber":{"$regex":"^054"}, "Name":"John"}
}
retrieve scores between 1000 and 3000, including the endpoints, we could issue:
{"score":{"$gte":1000,"$lte":3000}}'
retrieve scores equal to an odd number below 10, we could issue:
{"score":{"$in":[1,3,5,7,9]}}
retrieve an account where the date & time is greater than or equal to 2019-04-13 – 14:15:
{
"_method":"get",
"where":{"createdAt":{"$gte":{"__type":"Date","iso":"2019-04-13T14:15:00.000Z"}}}
}
Post- Add a new record
In order to add a new record to the Accounts table, simply delete the "_method":"get" line:
Add a new record with the name "Jo" and email "jo@jo.com":
{
"Name":"jo",
"Email":"jo@jo.com"
}
Put- update an existing record
In order to update an existing record in the table, we will use the put method and add to the URL the id we want to update after the table name:
The data is the same, we will only send what we want to update:
{
"Name":"NotJo",
"Email":"NotJo@jo.com"
}
Read here the complete manual of the Rest API: https://docs.parseplatform.org/rest/guide/