简体   繁体   English

SugarCRM中带有JSON正文的GET请求

[英]GET request with JSON body in SugarCRM

I'm using SugarCRM rest API, and according to the documentation , to get a set of records, I have to use /<module> GET endpoint and pass JSON in the body to filter the query. 我正在使用SugarCRM rest API,根据文档 ,要获取一组记录,我必须使用/<module> GET端点并在正文中传递JSON来过滤查询。

First, is it even possible to have a body in a GET request ? 首先,是否有可能在GET请求中包含主体?

and how can I build this kind of request then ? 那我该如何建立这种请求呢?

I'm using postman and tried to pass parameters as query strings but it's not possible though. 我正在使用邮递员,并尝试将参数作为查询字符串传递,但是这是不可能的。

As far as I know you have to put everything in the query string, which might look different to what you'd expect. 据我所知,您必须将所有内容都放入查询字符串中,这看起来可能与您期望的有所不同。

Example for a request to /Users : /Users请求的示例:

{
    max_num: 100,
    fields: ["first_name", "last_name"],
    filter: [
        {"user_name":"admin"}
        {"status":"Active"}
    ]
}

Written as query string this request will look like this: 作为查询字符串编写的此请求将如下所示:

/rest/v10/Users?max_num=100&fields=first_name,last_name&filter[0][user_name]=admin&filter[1][status]=Active

Observations regarding the query string format: 关于查询字符串格式的观察:

  • There is no { or } , the values of the request object are places directly in the query string 没有{} ,请求对象的值直接放在查询字符串中
  • Key-Value pairs are assigned with = , and separated by & (instead of : and , ) 键值对使用=分配,并用&分隔(而不是:,
  • There are no " or ' quotes at all, strings are written without those 根本没有"'引号,没有这些引号的字符串
  • An array of values (here: fields ) is just one assignment with all values separated by , 值数组(此处为fields )只是一个赋值,所有值之间用分隔,
  • An array of objects (here: filter ) has one Key-Value pair per bottom value and uses [ and ] to indicate the "path" to each value. 对象数组(此处为filter )的每个底值都有一个“键-值”对,并使用[]指示每个值的“路径”。 Using 0-based numerical indices for arrays 对数组使用基于0的数字索引

Notes 笔记

  • Keep in mind there are length limits to URL incl. 请注意,URL包括长度限制。 query string. 请求参数。 Eg 4096 bytes/chars for Apache 2, if I remember correctly. 如果我没记错的话,例如Apache 2的4096字节/字符。 If you have to send very elaborate requests, you might want to use POST /rest/v10/<module>/filter instead. 如果必须发送非常复杂的请求,则可能要改用POST /rest/v10/<module>/filter
  • URL-escaped (usually not necessary) the example filter would look like this: /rest/v10/Users?max_num%3D100%26fields%3Dfirst_name%2Clast_name%26filter%5B0%5D%5Buser_name%5D%3Dadmin%26filter%5B1%5D%5Bstatus%5D%3DActive 转义为URL(通常不是必需)的示例过滤器如下所示: /rest/v10/Users?max_num%3D100%26fields%3Dfirst_name%2Clast_name%26filter%5B0%5D%5Buser_name%5D%3Dadmin%26filter%5B1%5D%5Bstatus%5D%3DActive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM