Announcement

Collapse
No announcement yet.

API REST WHERE condition using OR

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • API REST WHERE condition using OR

    Hello!
    I was trying to implement the OR condition within WHERE in the api rest url, I searched everywhere but can't find any examples, according to the documentation:
    https://github.com/espocrm/documenta...arch-params.md

    I figured it out how to actually use it in a API call

    So...
    In my case i wanted to get all results where a field is equals or after for a given date, unfortunately i think there is not condition like greaterThanOrEquals for numeric fields so using the OR condition it should look like this:

    crm.exmaple.com/v1/Account?where[0][type]=or&where[0][value][0][type]=equals&where[0][value][0][attribute]=suscribedDate&where[0][value][0][value]=2020-03-26 19:05:01&where[0][value][1][type]=after&where[0][value][1][attribute]=suscribedDate&where[0][value][1][value]=2020-03-26 19:05:01

    So...

    This way we have this object

    Code:
    {[INDENT]"type": "or",
    "value": [[/INDENT][INDENT=2]{[/INDENT][INDENT=3]"type": "equals",
    "attribute": "suscribedDate",
    "value": "2020-03-26 19:05:01"[/INDENT][INDENT=2]},
    {[/INDENT][INDENT=3]"type": "after",
    "attribute": "suscribedDate",
    "value": "2020-03-26 19:05:01"[/INDENT][INDENT=2]}[/INDENT][INDENT]][/INDENT]
     }
    Code:
    where[0][type]=or
    where[0][value][0][type]=equals
    where[0][value][0][attribute]=suscribedDate
    where[0][value][0][value]=2020-03-26 19:05:01
    where[0][value][1][type]=after
    where[0][value][1][attribute]=suscribedDate
    where[0][value][1][value]=2020-03-26 19:05:01
    So, basically it is an nested array, following this logic we can add more complex conditions adding elements to the where array (where[1], where[2], where[n])

    If this is useful for someone im glad it helps, greetings!

    (Obviously english is not my first language, I hope is good enough)
Working...
X