1

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.

Azoulay Jason
  • 2,149
  • 4
  • 16
  • 36
  • Can you share one of the query strings you tried please. So that we can see if something is wrong with it. – Jay Jun 13 '18 at 18:51
  • 1
    Possible duplicate of [HTTP GET with request body](https://stackoverflow.com/questions/978061/http-get-with-request-body) – Evert Jun 13 '18 at 20:46

1 Answers1

2

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. E.g. 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
Jay
  • 1,927
  • 8
  • 15