[self-host] Correct Query Parameter Syntax for REST API Filtering (/rest/people)
Hello everyone,
I'm working with a self-hosted instance of Twenty and I'm struggling to correctly filter the GET /rest/people endpoint via query parameters. My goal is to find a person by their name or email, but all my attempts seem to return the full, unfiltered list of contacts.
After trying to use the GraphQL API without success, we've focused on the REST API based on community examples, but we still can't get the filtering to work.
Here are three examples of syntaxes we have already tested unsuccessfully:
Using bracket notation with [contains] for the name:
We tried to filter by a partial name, expecting this to work based on some online examples.
GET /rest/people?displayName[contains]=Patricia
Using bracket notation with [equals] for the email:
Similarly, we tried to get an exact match for an email address.
GET /rest/people?email[equals]=test@example.com
Targeting nested fields for the name:
Since we learned from GraphQL that the name might be an object, we also tried to filter on a sub-field.
GET /rest/people?name[firstName][contains]=Patricia
Unfortunately, none of these methods have worked for us. Could someone please clarify what the correct parameter syntax is for filtering people on a self-hosted instance?
Specifically, we need to know how to filter by:
A name field (partial match, like contains).
An email field (exact match).
Thank you in advance for any guidance!
1 Reply
Try this for GraphQL:
query people($email: String!) {
people(filter:{emails:{primaryEmail:{eq:$email}}}
,first:1000) {
edges{
node{
id
name{
firstName
lastName
}
emails{
primaryEmail
}
company {
name
position
id
accountOwner{
name{
firstName
lastName
}
userEmail
}
domainName{
primaryLinkUrl
}
}
}
}
}
}
For the variable to be passed :
{
"email": "valid email"
}
And your result will be like:
{
"data": {
"people": {
"edges": [
{
"node": {
"id": "0ee6abbb-0156-446c-8b9c-7806f9460044",
"company": null,
"name": {
"firstName": "the name",
"lastName": "the last name"
},
"emails": {
"primaryEmail": "the email you placed"
}
}
}
]
}
}
}
of course you can adjust the fields of the query to add custom fields
you can change them to list with in operator and change the String to [String!] and of course your input