Complex GraphQL search: including a ticket category, but excluding another

I’m looking to find all open tickets, which are in category ID 40, but NOT in category ID 2.

I think my query is super close… but not quite there.
It’s still including those in category 2, because I think it’s treating the array of search parameters as “additive” instead of “combined” … if that makes any sense.

query CoolQuery($search: Search, $rrf:ReverseRelationFilter){
  tickets(search: [$search], reverse_relation_filters:[$rrf]){
    entities{
      id
      subject
      status
      ticket_categories {
              entities{
                id
                name
                created_at
              }
            }
    }
  }
}

Variables:

{
  "rrf":{
    "relation": "ticket_categories",
    "search": [
      {
        "integer_fields": [
          {
            "attribute": "id",
            "search_value": 40,
            "operator": "EQ"
          },
          {
            "attribute": "id",
            "search_value": 2,
            "operator": "NEQ"
          }
        ]
      }
      ]
  },
  "search":{
    "string_fields": [
      {
        "attribute": "status",
        "search_value": "OPEN",
        "match": true,
        "partial_matching": false
      }
    ]
  }
}

Any ideas? @simon

From taking a quick glance at the API docs, it doesn’t appear there is a way to specify whether you would like the list of search fields to be logically ANDed instead of ORed… it appears the default is the latter. Maybe I missed it? That would be a nice feature if it’s not already there!

In the mean time you could of course filter on one criteria via the query and filter on the other application side.

Hey Tim! GraphQL Expects an array of reverse relation filters. I made some corrections, hopefully this works for you.

{
    "rrf": [
        {
            "relation": "ticket_categories",
            "search": [
                {
                    "integer_fields": [
                        {
                            "attribute": "id",
                            "search_value": "40",
                            "operator": "EQ"
                        },
                        {
                            "attribute": "id",
                            "search_value": "2",
                            "operator": "NEQ"
                        }
                    ]
                }
            ]
        }
    ]
}

Yes, this is possible. You need to use the group attribute in the RRF. See below:

The way you’re doing it, it will be an OR, because referencing the same field in the same RRF is always an OR. However, if you build two separate RRFs, and set the group parameter to the same thing (e.g. 1) then it will AND them together.

moved post here since it’s a new topic:

ticket_recipients must be an array, as indicated by the API docs

"ticket_recipients": [{
  "email_address": "my@email.com",
  "name":  "My Name" 
}]
1 Like

AHHH missed the brackets. thanks!

Nice to see people leveraging some of the power of the new API!