helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API
MIT License
98 stars 62 forks source link

Custom Fields: Dates/Queries #232

Closed JonLaliberte closed 4 years ago

JonLaliberte commented 4 years ago

I noticed that we could use a query to search for custom text fields using the * wildcard and this will list all conversations where that custom field is not empty.

But this query doesn't work for dates. Is there any way to return all conversations that have any date set for a (date) custom field? (Same goes for the other non-text fields, I haven't tested them all though)

Is it possible to search for a date custom field before/after/between?

bkuhl commented 4 years ago

That's a great question, let me do some digging and I'll see what I can find out!

bkuhl commented 4 years ago

Hey Jon,

I'm sorry about the delay in the response, but I have some answers for you. The key here is going to be to use ConversationFilters::withQuery(). Depending on what you're wanting to do, here's how you can accomplish it for custom date fields:

Date Fields

Condition withQuery()
Before cf{FIELD_ID}:[* TO 2020-02-15T00:00:00Z]
After cf{FIELD_ID}:[2020-02-15T00:00:00Z TO *]
Between cf{FIELD_ID}:[2020-02-29T00:00:00Z TO 2020-03-05T00:00:00Z]
Value is not empty cf{FIELD_ID}:[* TO *]

Example

$filters = (new ConversationFilters())
    ->withMailbox(138367)
    ->withStatus('all')
    ->withQuery('cf20070:[* TO *]');
$conversations = $client->conversations()->list($filters);
JonLaliberte commented 4 years ago

@bkuhl Fantastic, thank you!!

JonLaliberte commented 4 years ago

@bkuhl This is working great, thanks! One more question though... What if we want to search for a custom date field that IS empty? I tried a few things in the GUI (null, empty quotes, etc), but couldn't find a query that worked.