简体   繁体   中英

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.

First, is it even possible to have a body in a GET request ?

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 :

{
    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 ,
  • An array of objects (here: filter ) has one Key-Value pair per bottom value and uses [ and ] to indicate the "path" to each value. Using 0-based numerical indices for arrays

Notes

  • Keep in mind there are length limits to URL incl. query string. Eg 4096 bytes/chars for Apache 2, if I remember correctly. If you have to send very elaborate requests, you might want to use POST /rest/v10/<module>/filter instead.
  • 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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