Sugarcrm支持产品指南糖开发人员糖开发人员指南10.3食谱网页服务休息API.抨击如何过滤记录列表
此版本仅适用于Sugarcloud客户。

如何过滤记录列表

概述

An example in bash script demonstrating how to filter records using the v11 /<module>/filter REST POST endpoints.

过滤记录

验证

首先,您需要对Sugar API进行身份验证。一个例子如下所示:

curl -X POST -H Cache-Control:no-cache -H "Content-Type: application/json" -d '{ 
 "grant_type":"password",
 "client_id":"sugar",
 "client_secret":"",
 "username":"admin",
 "password":"password",
 "platform":"custom_api"
}' //{site_url}/rest/v11/oauth2/token

有关验证的更多信息可以在其中找到 如何进行身份验证和注销 示例和 / oauth2 / logout 端点文档。

过滤记录

Next we can filter the records we want to return using the /<module>/filter endpoint with a POST request.

curl -s -X POST -H OAuth-Token:{access_token} -H "Content-Type: application/json" -H Cache-Control:no-cache -d '{  
   "filter":[  
      {  
         "$or":[  
            {  
               "name":{  
                  "$starts":"A"
               }
            },
            {  
               "name":{  
                  "$starts":"b"
               }
            }
         ]
      }
   ],
   "max_num":2,
   "offset":0,
   "fields":"id",
   "order_by":"date_entered",
   "favorites":false,
   "my_items":false
}' //{site_url}/rest/v11/Accounts/filter

可以在滤波器API上找到更多信息 /<module>/filter documentation.

笔记 : The /<module>/filter endpoint can be called using a GET request as well, though long URL requests can have issues so the POST request is recommended. 

回复

从服务器接收的数据如下所示:

{  
   "next_offset":2,
   "records":[  
      {  
         "id":"f16760a4-3a52-f77d-1522-5703ca28925f",
         "date_modified":"2016-04-05T10:23:28-04:00",
         "_acl":{  
            "fields":{  

            }
         },
         "_module":"Accounts"
      },
      {  
         "id":"ec409fbb-2b22-4f32-7fa1-5703caf78dc3",
         "date_modified":"2016-04-05T10:23:28-04:00",
         "_acl":{  
            "fields":{  

            }
         },
         "_module":"Accounts"
      }
   ]
}

最后修改:2021-01-06 23:28:41