I’m trying to filter queries by custom field using the REST API. I have a custom field (“Tags”) of type “select multiple values”. I have a ticket that has the Tags field set to “Project”. This advanced query in the web UI correctly shows no tickets matching:
id = 30194 AND CF.{Tags} NOT LIKE 'Project'
Using that exact query string in the REST API returns ticket 30194.
How can I filter tickets by CF using the REST API?
Thanks,
Keith
Oh, good question. REST1, it appears. I’ll try REST2.
Thanks.
1 Like
I get the same with REST2. These two query strings both return ticket 30194:
id = 30194 AND CF.{Tags} NOT LIKE 'Project'
id = 30194 AND CF.{Tags} LIKE 'Project'
What is the value of the Tags CF for 30194? Can you share your code that is doing the REST2 query?
Tags CF:
"CustomFields" : [
...
{
"_url" : redacted,
"values" : [
"Out-of-Hours",
"Project"
],
"id" : "7",
"type" : "customfield",
"name" : "Tags"
}
Code:
#!/usr/bin/python3
import requests
import urllib.parse
RT_TOKEN = "redacted"
RT_REST2 = "https://redacted/REST/2.0"
headers = {'Authorization': f'token {RT_TOKEN}'}
# query = "id = 30194 AND CF.{Tags} LIKE 'Project'"
query = "id = 30194 AND CF.{Tags} NOT LIKE 'Project'"
url = f'{RT_REST2}/tickets?query={urllib.parse.quote(query)}'
r = requests.get(url, headers=headers)
print(r.text)
RT version, which I omitted before, is 4.4.3.