Fetch Records
Table of Contents
Note: This task is applicable to all Zoho Services except Zoho Creator.
Overview
This task is used to fetch a list of records from a Zoho Cliq database, based on a given criteria.
This task is based on Zoho Cliq API - List Records.
Syntax
<variable> = zoho.cliq.getRecords(<database_name>, <query_map>, <connection>);
Params | Data type | Description |
<variable> | KEY-VALUE | specifies the variable which will hold the response returned by Zoho Cliq. |
<database_name> | TEXT | specifies the unique name of the database from which the records will be fetched |
<query_map> | KEY-VALUE | specifies the query parameters to fetch specific records. The applicable query params can be found here. Click here to find the list of applicable operators that can be used to specify multiple values in criteria. Note: You can provide an empty map in which case all the records will be fetched. |
<connection> | TEXT | specifies the link name of the Zoho Cliq connection. Note:
|
Example1: Fetching records that satisfy static criteria
The following example fetches all the records from the database - availabilitydatabase that has a value - true in the column - availability.
query_map=Map(); query_map.put("criteria","availability==true"); response_map=zoho.cliq.getRecords("availabilitydatabase",query_map, "cliq_connection");
where,
response_map
"availabilitydatabase"
query_map
"criteria"
"availability==true"
"cliq_connection"
Example2: Fetching records that satisfy dynamic criteria
Write the below script in the message handler of your Bot configuration to make it search and fetch records from the Zoho Cliq database - availabilitydatabase. The search condition is altered based on the user's response.
If the user sends YES to the Bot, the condition is set to availability==true. Thus, it fetches and displays all the records with value - true in the availability field.
Otherwise, the condition is availability==false. Thus, it fetches and displays all the records with value - false in the availability field.
response = Map(); dynamic_value = false; if(message.containsIgnoreCase("YES")) { dynamic_value = true; } query = "availability=="+dynamic_value; text = zoho.cliq.getRecords("availabilitydatabase", {"criteria":query}, "cliq_connection"); response.put("text",text); return response;
where,
message
text
"availabilitydatabase"
"criteria"
query
dynamic_value
The following is the response of the above script when the user sends YES.
Sample Response
Success Response
The success response returned is of the following format
{
"status":"SUCCESS",
"url":"/api/v2/storages/availabilitydatabase/records",
"list":
[{"empid":"6","name":"John","availability":true,"id":"1775XXXX0002XXX431"},
{"empid":"5","name":"Austin","availability":true,"id":"1775XXXX0002XXX469"},
{"empid":"1","name":"Hanna","availability":true,"id":"1775XXXX0002XXX009"},
{"empid":"2","name":"Kate","availability":true,"id":"1775XXXX0002XXX039"}]
}
To fetch the ID of the newly created record, execute the following snippet:
for each <loop_variable> in <var1>
{
info <loop_variable>.get("id");
}
Failure Response
The failure response returned for an incorrect database name is of the following format
{
"status":"FAILURE",
"message":"Uh-oh! Looks like availabilitydata does not exist.",
"code":"platform_storage_database_not_found"
}The failure response returned for an incorrect or non-existent field name is of the following format
{
"status":"FAILURE",{
"message":"The designation column does not exist.",
"code":"platform_storage_column_not_exists"
}The failure response for a data type mismatch is of the following format
{
"status":"FAILURE",
"message":"Invalid value given for field empid value Austin.",
"code":"platform_storage_fields_invalid_value"
}The failure response for an invalid operator in criteria field is of the following format
{
"status":"FAILURE",
"message":"Oops! Invalid operator specified for the criteria true",
"code":"platform_storage_invalid_criteria_operator"
}
Related Tasks
- Zoho Cliq API
- Common error codes can be viewed here