-
Notifications
You must be signed in to change notification settings - Fork 62
Filter and Search Lists
GET
https://example.com/wp-json/dt/v1/{contacts||groups}/search
- Replace
example.com
with your domain - Replace
{contacts||groups}
with eithercontacts
orgroups
sort (string)
- Options:
- name //name or title of the record
- assigned_to
- last_modified //date of the last comment or edit
- post_date //creation date of the record
- locations
- Options for contacts:
- overall_status
- seeker_path
- faith_milestones
- groups
- Options for groups:
- leaders
- group_status
- group_type
- members
Add a -
before any of these options to return them in descending order
Example:
// get records assigned to me, ordered by creation date from newest to oldest
let searchParameters = {
assigned_to: [ 'me' ],
sort: `-post_date`
}
assigned_to (array) of presets or ids to filter:
- all // default for dispather
- me // default for multiplier
- shared // records that have been shared with me
- 83 // records assigned to user 83
- 84
Example:
// get records assigned to me
let searchParameters = {
assigned_to: [ 'me' ]
}
// get records assigned_to user 22 and user 48
let searchParameters = {
assigned_to: [ 22, 48 ]
}
key_select, multi_select (array)
- overall_status (contacts)
- group_status (groups)
- status (other post types)
- milestones
- age
- etc
Build as an array of the option keys to filter to.
Example:
// get contacts that have the 'Has Bible' or 'Reading Bible' milestones and that are at the 'Meeting Scheduled' stage.
let searchParameters = {
milestones: [ 'milestone_has_bible', 'milestone_reading_bible' ],
seeker_path: [ 'scheduled' ]
}
connections (array)
- locations
- subassigned
Build as an array of ids filter to.
Example:
// get contacts subassigned to contact 93
let searchParameters = {
subassinged: [ 93 ]
}
For the subassigned filter, add a combine:[ 'subassigned' ] when filtering for an assigned_to to search for either the assigned_to OR the subassigned. Otherwise it will search for contacts that are assigned to the selected user and subassigned to the select contact. Example:
// get contacts assigned_to user 22 **OR** subassigned to contact 93
let searchParameters = {
assigned_to [ 22 ],
subassinged: [ 93 ],
combine: [ 'subassigned' ]
}
date
- created_on // date the record was created
- baptism_date
- etc
Example:
// get the records created between in 2018
let searchParameters = {
created_on : {
start: "2018-01-01",
end: "2019-01-01"
}
}
// get contacts baptized before Feb 2019
let searchParameters = {
baptism_date : {
end: "2019-02-01"
}
}
Boolean (array)
- requires_update
- etc
"1" for true, "0" for false
Example:
// get contacts subassigned to contact 93
let searchParameters = {
requires_update: [ "1" ]
}
text (string) searches contact or group names/titles and contact information (email, phone etc)
Example:
// search for "Bob"
let searchParameters = {
text: "Bob"
}
offset (integer) the number of records to skip. Each page will contain a maximum of 100 records
Example:
// get second page of records 100
let searchParameters = {
offset: 100
}
After building the filter parameters, we need to transform the searchParameters object in the query parameters string. The query string needs to be the same format that jQuery.param() outputs. See here for a plain js alternative
let searchParameters = {
overall_status: ["active", "-closed"] // -closed filters out the closed records
seeker_path: ["none"]
sort: "post_date"
sources: ["instagram"]
}
let queryParametersString = jQuery.param(searchParameters)
// this gives a string that looks like this:
// seeker_path%5B%5D=none&overall_status%5B%5D=active&overall_status%5B%5D=-closed&sources%5B%5D=instagram&sort=post_date
//query away with:
let queryString = `https://example.com/wp-json/dt/v1/contacts/search?${queryParametersString}`;
//for contacts
{
contacts: [
{ ... contact1 ... },
{ ... contact2 ... }
],
total: 339 // the total number of contacts available to page (see offset)
}
//for groups
{
groups: [
{ ... group1 ... },
{ ... group2 ... }
],
total: 34 // the total number of groups available to page (see offset)
}