helpscout / helpscout-api-php

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

Query results different from UI? #249

Closed JonLaliberte closed 4 years ago

JonLaliberte commented 4 years ago

Thank you for taking the time to submit an issue with all the details shown below. Our engineering team monitors issues submitted and strives to respond with 1-2 business days.

Current behavior We are trying to run a query, but for some reason some conversations are being returned that we do not want included.

Expected behavior / Steps to reproduce

Here is the code:

$ignoreTags = ' AND -tag:whatever AND -tag:whatever else'; // This is built earlier in the code, but this is the format
$filters = (new ConversationFilters())
->inMailbox(99999999)
->inStatus('pending')
->withQuery('-cf99999999999:[NOW TO *] AND modifiedAt:[NOW-180DAYS TO NOW-9DAYS]' . $ignoreTags);

If I echo the query string and run it in the HelpScout UI, it works and shows the conversations I expect. But when the code runs, it returns some conversations that shouldn't be returned. Specifically, the tags don't seem to be being negated.

bkuhl commented 4 years ago

Hey Jon,

Looking through our logs I can see the request coming in you've made. Can you give me an example conversation that is included in the results that shouldn't be?

JonLaliberte commented 4 years ago

Hey Ben,

Thanks for looking in to this.

Here are a few: 1215455703, 1215037702, 1214701924

I did some more testing just now, which you'll see polluting the logs a bit, but after seeing your reply I had a suspicion I wanted to confirm. I figured maybe the spaces in that second tag were causing problems. In the UI, when you enter in a tag with spaces, it displays it as I showed in my code example above, but it must be quoting those behind the scenes. I tested just now using a quoted string for the tags with spaces and I believe it resolves the issue.

bkuhl commented 4 years ago

Yep! That'll do it. The query docs actually indicate when querying by tags they should be quoted. I believe this would serve as an alternative to escaping the spaces.

Screen Shot 2020-07-14 at 1 57 42 PM

JonLaliberte commented 4 years ago

Sorry about that Ben, embarrassed I didn't catch this earlier. I think I was getting distracted when switching between the frontend docs and the actual query docs and didn't see it there. My bad.

bkuhl commented 4 years ago

It happens to all of us Jon, don't worry about it :)