This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UCCS API email filtering granularity

I'm wondering if anyone has had any exepreience with the REST API and filetering emails by the hour?

For example:

The following Query returns the entire days worth of email even though I'm looking for only the last hours worth...

var messages = await m_client.
For(x.EmailMessages).
WithinLast(1, RelativeDate.Hour).
Where(x.Direction == 2). //inbound, 3 is outbound
Select(x.Key, x.Sender.EmailAddress.DisplayName, x.Sender.EmailAddress.Name, x.SendDate, x.Subject, x.Recipients.EmailAddress.Name, x.Recipients.EmailAddress.Person.Department, x.Direction).
QueryAllAsync();

I have also tried using between with DateTimes that are hour lone with the same results...  and help or suggestions are appreciated.

Top Replies

Parents Reply
  • Thanks David, yes I saw that in the document as well.  Now I know, so what I can do is allow my client application that queries for a given day to further filter on the time portion.  Appreciate the direction on this!

    Jamie

Children
  • I have more on this

    You could try to add a second 'where' clause against the Message Date

    (i.e. x.MessageDate) where >= $dateValue.

    $dateValue would be a Powershell date that is computed using Get-Date and then AddHours(-1)

    The WithinLast part selects the shard and this additional filter should limit the messages in that shard.

    Please let me know if you have any additional questions.

  • That's the trick.  Works perfectly... thanks so much.

    For reference here is my code (in C#)

    var messages = await m_client.
    For(x.EmailMessages).
    Between(DateTime.UtcNow, DateTime.UtcNow).
    Where(x.Direction == 2). //Direction: 1 is internal, 2 is inbound, 3 is outbound
    Where(x.SendDate > DateTime.UtcNow.AddHours(-1)).
    Select(x.Key, x.Sender.EmailAddress.DisplayName, x.Sender.EmailAddress.Name, x.SendDate, x.Subject, x.Recipients.EmailAddress.Name, x.Recipients.EmailAddress.Person.Department, x.Direction).
    QueryAllAsync();