Search code examples
drupaljson-api

Drupal JSON API: how to filter using "different than"?


I'm trying to write a very simple JSON API query on Drupal 8: return all users except uid 0 and 1. Sounds trivial enough but I haven't been able to figure it out and to find any example.

Something like this?

jsonapi/user/user?filter[drupal_internal__uid]!=0

Any ideas would be most welcome!


Solution

  • Something like this should work as you want:

    /jsonapi/user/user?filter[user-uid][condition][path]=uid&filter[user-uid][condition][operator]=NOT IN&filter[user-uid][condition][value][]=0&filter[user-uid][condition][value][]=1
    

    For more informations: https://www.drupal.org/node/2943641

    Edit: If you use cURL, brackets will throw an error, add "--globoff" to your request.

    Example:

    curl --globoff --location --request GET "{{localhost}}/jsonapi/node/article?sort=nid&page[limit]=10&filter[article-title][path]=title&filter[article-title][value]=headless&filter[article-title][operator]=NOT%20IN".

    Reference: https://stackoverflow.com/a/8333999/5052969