Querying Data by Condition
Function
This API is used to query data by condition.
URI
POST Huawei Cloud Astro Zero domain name/u-route/baas/data/v1.0/query/{objectName}?base=X&fields=f1,f2
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
objectName |
Yes |
String |
Explanation Data object name. For details, see Logging In to the Application Designer. You can access the application designer and choose Data > Object to view data object names. Constraints None Value 1–80 characters Default value None |
base |
No |
String |
Explanation Query parameter, which is used to distinguish the data passed by objectName. Constraints None Value The options are as follows:
Default value None |
fields |
No |
Array |
Explanation Field displayed in an object. Set this parameter to the unique ID of a field. Use commas (,) to separate multiple fields. If this parameter is specified, only the specified fields and necessary information (for example, data record owner and the owner ID) are returned. If this parameter is left unspecified, the entire data record is returned.
Constraints None |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
condition |
No |
Object |
Explanation Query condition. If this parameter is left unspecified, all object data is queried. This parameter contains the following elements:
Constraints None |
relation |
No |
Object |
Explanation Associated query, including parents (upward query) and children (downward query). The parents field contains the condition array and relatedField (name of the associated field). The children field contains the condition array and relationName (name of the associated field). The condition array contains conjunction, conditions, and relation. The parameter description is the same as that of condition. {
//Upward query
parents: [//Level-1 parent object
{
relatedField: "CarHolder__CST", // Current object field (Lookup/MasterDetail type), which is used to determine the parent object
options: {
fields: ["id", "name", "Age__CST"] // Field to be queried of the parent object
},
parents: [// (Optional) Level-2 parent object
{
relatedField: "cust__CST," // Parent object field (Lookup/MasterDetail type), which is used to determine the grandparent object
options: {
fields: ["id", "name", "Email__CST"] // Field to be queried of the grandparent object
}
}
]
}
],
//Downward query
childs: [//Level-1 child object
{
relationName: "Contacts," // Child object relationship name (specified when Lookup/MasterDetail is defined for a child object). The child object is determined based on the relationship name.
options: {
fields: ["id", "name", "Age__CST", "cust__CST"] // Child object field to be queried
},
childs: [// (Optional) Level-2 child object
{
relationName: "ContactCars", // Relationship name of the grandchild object
options: {
fields: ["id", "name", "Price__CST", "CarHolder__CST"] // Grandchild object field to be queried
}
}
]
}
]
} Constraints None |
options |
No |
Object |
Explanation Additional option, which is used to perform operations on the query result.
Constraints None |
Response Parameters
Parameter |
Type |
Description |
---|---|---|
resCode |
String |
Explanation Return code. Value If the request is successful, 0 is returned. For details about other error codes, see Error Codes. |
resMsg |
String |
Explanation Message returned. Value If the request is successful, Success is returned. In other cases, an error message is returned. |
result |
Array |
Explanation Returned object data. |
count |
number |
Explanation Total number of records that meet the conditions in the object. Value None |
Example Request
POST https://Huawei Cloud Astro Zero domain names /u-route/baas/data/v1.0/query/TestProject__testForObject1__CST?base=N
{"condition": {
"conjunction": "AND",
"conditions": [
{
"field": "name",
"operator": "eq",
"value": "zhang"
}
]
},
"options": {
"orderby": [
{
"field": "TestProject__length__CST",
"order": "desc"
}
],
"limit": 3
}
}
Example Response
{
"resCode": "0",
"resMsg": "Success",
"result": [
{
"TestProject__age__CST": null,
"TestProject__length__CST": "888",
"TestProject__name__CST": null,
"createdBy": "10gd000000SDzgxNSckK",
"createdBy.__objectType": "User",
"createdBy.name": "test0xx",
"createdDate": "2020-05-29 12:50:59",
"currencyIsoCode": "",
"id": "cglE000000aMGHkvmhmb",
"installedPackage": null,
"lastModifiedBy": "10gd000000SDzgxNSckK",
"lastModifiedBy.__objectType": "User",
"lastModifiedBy.name": "test0xx",
"lastModifiedDate": "2020-05-29 12:50:59",
"name": "zhang",
"owner": "10gd000000SDzgxNSckK",
"owner.__objectType": "User",
"owner.name": "test0xx"
},
{
"TestProject__age__CST": null,
"TestProject__length__CST": "456",
"TestProject__name__CST": null,
"createdBy": "10gd000000SDzgxNSckK",
"createdBy.__objectType": "User",
"createdBy.name": "test0xx",
"createdDate": "2020-05-29 12:50:59",
"currencyIsoCode": "",
"id": "cglE000000aMGHkvmhma",
"installedPackage": null,
"lastModifiedBy": "10gd000000SDzgxNSckK",
"lastModifiedBy.__objectType": "User",
"lastModifiedBy.name": "test0xx",
"lastModifiedDate": "2020-05-29 12:50:59",
"name": "zhang",
"owner": "10gd000000SDzgxNSckK",
"owner.__objectType": "User",
"owner.name": "test0xx"
},
{
"TestProject__age__CST": null,
"TestProject__length__CST": "17",
"TestProject__name__CST": null,
"createdBy": "10gd000000SDzgxNSckK",
"createdBy.__objectType": "User",
"createdBy.name": "test0xx",
"createdDate": "2020-05-29 12:43:11",
"currencyIsoCode": "",
"id": "cglE000000aMFjB9ipAu",
"installedPackage": null,
"lastModifiedBy": "10gd000000SDzgxNSckK",
"lastModifiedBy.__objectType": "User",
"lastModifiedBy.name": "test0xx",
"lastModifiedDate": "2020-05-29 12:43:11",
"name": "zhang",
"owner": "10gd000000SDzgxNSckK",
"owner.__objectType": "User",
"owner.name": "test0xx"
}
],
"count": 5
}
Status Code
See Status Codes.
Error Code
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot